【问题标题】:Azure Graph API call doesn't have refresh tokenAzure Graph API 调用没有刷新令牌
【发布时间】:2016-11-29 15:05:09
【问题描述】:

我正在尝试使用我的应用程序访问图形 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 的调用以通过调用获取刷新令牌?

【问题讨论】:

    标签: c# asp.net azure-ad-graph-api


    【解决方案1】:

    我通过将 Active Directory 身份验证库从 v2.0.0 更新到 v2.28.3 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2021-05-13
      • 1970-01-01
      • 1970-01-01
      • 2022-07-15
      • 2019-10-26
      • 2020-12-19
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      相关资源
      最近更新 更多