public static JObject GetTokenForResourceFromExistingToken(string oauthType, string redirect, JToken tokenWithRefresh, string resource) { JObject tokenObj; using (HttpClient httpClient = new HttpClient()) { string tenantId = AzureUtility.GetTenantFromToken(tokenWithRefresh); string refreshToken = AzureUtility.GetRefreshToken(tokenWithRefresh); string tokenUrl = string.Format(Constants.AzureTokenUri, tenantId); var tokenMeta = GetMetaFromOAuthType(oauthType); string token = AzureTokenUtility.GetTokenBodyFromRefreshToken(refreshToken, resource, redirect, tokenMeta.ClientId); StringContent content = new StringContent(token); content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); string response2 = httpClient.PostAsync(new Uri(tokenUrl), content).Result.Content.AsString(); tokenObj = JsonUtility.GetJsonObjectFromJsonString(response2); } return(tokenObj); }
public static JObject GetTokenForResource(ActionRequest request, JToken azureToken, string resource) { JObject tokenObj; using (HttpClient httpClient = new HttpClient()) { string tenantId = AzureUtility.GetTenantFromToken(azureToken); string refreshToken = AzureUtility.GetRefreshToken(azureToken); string tokenUrl = string.Format(Constants.AzureTokenUri, tenantId); string clientId = GetAzureToken.GetClientIdFromRequest(request); string token = GetAzureToken.GetTokenUri2(refreshToken, resource, request.Info.WebsiteRootUrl, clientId); StringContent content = new StringContent(token); content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); string response2 = httpClient.PostAsync(new Uri(tokenUrl), content).Result.Content.AsString(); tokenObj = JsonUtility.GetJsonObjectFromJsonString(response2); } return(tokenObj); }