Azure Graph API 调用没有刷新令牌
Azure Graph API call doesn't have refresh token
我正在尝试使用我的应用程序访问图表 api 并且它是成功的,但是,当令牌过期时,我没有刷新令牌来刷新我的设置,然后我的应用程序停止工作直到我重新发布该应用程序并生成一个新令牌。
这是我通过 AJAX 调用的代码,用于从图表 api:
中获取数据
[Authorize]
public async Task<UserProfile> UserProfile()
{
string tenantId = ClaimsPrincipal.Current.FindFirst(TenantIdClaimType).Value;
// Get a token for calling the Windows Azure Active Directory Graph
AuthenticationContext authContext = new AuthenticationContext(String.Format(CultureInfo.InvariantCulture, LoginUrl, tenantId));
ClientCredential credential = new ClientCredential(AppPrincipalId, AppKey);
AuthenticationResult assertionCredential = authContext.AcquireToken(GraphUrl, credential);
string authHeader = assertionCredential.CreateAuthorizationHeader();
string requestUrl = String.Format(
CultureInfo.InvariantCulture,
GraphUserUrl,
HttpUtility.UrlEncode(tenantId),
HttpUtility.UrlEncode(User.Identity.Name));
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
request.Headers.TryAddWithoutValidation("Authorization", authHeader);
HttpResponseMessage response = await client.SendAsync(request);
string responseString = await response.Content.ReadAsStringAsync();
UserProfile profile = JsonConvert.DeserializeObject<UserProfile>(responseString);
profile.Username = User.Identity.Name.Replace("@xxx.com", "");
return profile;
}
运行 通过这个,当我得到我的 assertionCredential
时,它有一个访问令牌、accessTokenType 和一个到期日期(从它创建后 1 小时),但刷新令牌为空。我是否需要编辑对 API 的调用以通过调用获取刷新令牌?
我通过将 Active Directory 身份验证库从 v2.0.0 更新到 v2.28.3 解决了这个问题。
我正在尝试使用我的应用程序访问图表 api 并且它是成功的,但是,当令牌过期时,我没有刷新令牌来刷新我的设置,然后我的应用程序停止工作直到我重新发布该应用程序并生成一个新令牌。
这是我通过 AJAX 调用的代码,用于从图表 api:
中获取数据[Authorize]
public async Task<UserProfile> UserProfile()
{
string tenantId = ClaimsPrincipal.Current.FindFirst(TenantIdClaimType).Value;
// Get a token for calling the Windows Azure Active Directory Graph
AuthenticationContext authContext = new AuthenticationContext(String.Format(CultureInfo.InvariantCulture, LoginUrl, tenantId));
ClientCredential credential = new ClientCredential(AppPrincipalId, AppKey);
AuthenticationResult assertionCredential = authContext.AcquireToken(GraphUrl, credential);
string authHeader = assertionCredential.CreateAuthorizationHeader();
string requestUrl = String.Format(
CultureInfo.InvariantCulture,
GraphUserUrl,
HttpUtility.UrlEncode(tenantId),
HttpUtility.UrlEncode(User.Identity.Name));
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
request.Headers.TryAddWithoutValidation("Authorization", authHeader);
HttpResponseMessage response = await client.SendAsync(request);
string responseString = await response.Content.ReadAsStringAsync();
UserProfile profile = JsonConvert.DeserializeObject<UserProfile>(responseString);
profile.Username = User.Identity.Name.Replace("@xxx.com", "");
return profile;
}
运行 通过这个,当我得到我的 assertionCredential
时,它有一个访问令牌、accessTokenType 和一个到期日期(从它创建后 1 小时),但刷新令牌为空。我是否需要编辑对 API 的调用以通过调用获取刷新令牌?
我通过将 Active Directory 身份验证库从 v2.0.0 更新到 v2.28.3 解决了这个问题。