2017-06-01 44 views
0

私は、アプリケーションへのユーザーアクセスのためにActive Directoryを使用しています(私はアプリを作成してADに登録しました)が、トークンレスポンスからリフレッシュトークンを取得するのに問題があります。Azure Active Directoryトークン+リフレッシュトークン

はStartup.csに私はオープン同上接続オプションを定義します。

app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); 

     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      SlidingExpiration = true 
     }); 

     app.UseOpenIdConnectAuthentication(
      new OpenIdConnectAuthenticationOptions 
      { 
       ClientId = ApiConstants.AAD_WebClientId, 
       Authority = Authority, 
       TokenValidationParameters = new TokenValidationParameters { SaveSigninToken = true, }, 
       Notifications = new OpenIdConnectAuthenticationNotifications() 
       { 
        RedirectToIdentityProvider = context => 
        { 
         if (context.ProtocolMessage.RequestType == OpenIdConnectRequestType.AuthenticationRequest) 
         { 
          // ensure https before redirecting to Azure 
          if (!context.Request.IsSecure) 
          { 
           context.Response.Redirect(
            $"https://{context.Request.Uri.Authority}{context.Request.Uri.AbsolutePath}"); 
           context.HandleResponse(); 
           return Task.FromResult(0); 
          } 
         } 

         return Task.FromResult(0); 
        }, 

        // If there is a code in the OpenID Connect response, 
        // redeem it for an access token and refresh token, and store those away. 
        AuthorizationCodeReceived = OnAuthorizationCodeReceived, 
        AuthenticationFailed = OnAuthenticationFailed 
       } 
      }); 

マイOnAuthorizationCodeReceived方法は次のとおりです。

private async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedNotification context) 
    { 
     var code = context.Code; 

     ClientCredential credential = new ClientCredential(ApiConstants.AAD_WebClientId, ApiConstants.AAD_CertWeb); 
     AuthenticationContext authContext = new AuthenticationContext(Authority); 

     // If you create the redirectUri this way, it will contain a trailing slash. 
     // Make sure you've registered the same exact Uri in the Azure Portal (including the slash). 
     var builder = new UriBuilder(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)); 
     builder.Scheme = "https"; 
     if (builder.Uri.IsDefaultPort) 
     { 
      builder.Port = -1; 
     } 
     //n.AuthenticationTicket.Properties.RedirectUri = builder.ToString(); 

     // this doesn't return a refresh token??? 
     AuthenticationResult result = 
      await 
       authContext.AcquireTokenByAuthorizationCodeAsync(code, builder.Uri, credential, 
        ApiConstants.AAD_Audience); 
    } 

問題があり、返されたトークンは、リフレッシュトークンを持って、またしません私たちがログアウトされているので、それは毎回滑っています。 Q:リフレッシュトークンのオン/オフを行うためにActive Directoryやアプリケーションで行うことはできますか?

それとも、私が更新トークンを受信して​​いますが、AuthenticationResultクラスは私に戻って、このプロパティを暴露されていないということでしょうか?

答えて

0

同じ問題を調査したときにちょうど見つからなかった。

あなたはフィドラーのようなツールを使用してネットワークトラフィックを監視する場合、あなたはrefresh_tokenが実際にそれだけで露出することはないですが、返される表示されます。

以下のリンクより詳しい情報が得られます。

http://www.cloudidentity.com/blog/2015/08/13/adal-3-didnt-return-refresh-tokens-for-5-months-and-nobody-noticed/

+0

ここでも https://dzimchuk.net/adal-distributed-token-cache-in-asp-net-core/良い説明です – DavidReid

関連する問題