2016-11-29 65 views
0

我試圖訪問圖形api與我的應用程序,它是成功的,但是,當令牌過期時,我沒有刷新令牌來刷新我的設置,然後我的應用程序停止工作,直到我重新發布應用程序,它會生成一個新的令牌。Azure圖形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調用以獲取我的調用的刷新令牌?

回答

0

我通過將Active Directory認證庫從v2.0.0更新到v2.28.3來解決此問題。