2016-11-29 8 views
0

アプリケーションでグラフAPIにアクセスしようとしていますが、トークンが期限切れになったときに成功しました。アプリケーションを再公開して新しいトークンを生成するまで、私のアプリケーションは動作を停止します。Azure Graph APIコールにリフレッシュトークンがありません

ここで私はグラフAPIからデータを取得するためにAJAX経由で呼び出すコードです:これを走る

[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時間)、リフレッシュトークンはNULLです。私の呼び出しで更新トークンを取得するには、APIへの呼び出しを編集する必要がありますか?

答えて

0

これを解決するには、Active Directory認証ライブラリをv2.0.0からv2.28.3に更新します。

関連する問題