2017-02-13 9 views
1

새로 고침 토큰을 가져 오는 데 문제가 있습니다. 처음에는 ADAL의 웹보기를 사용하여 로그인하고 토큰을받습니다. 이 토큰은 만기 될 때까지 웹 API를 호출하는 데 사용됩니다. 예상대로 웹 프롬프트없이 새 토큰을 얻는 대신 오류가 서버에 기록되고 사용자에게 로그인 웹 프롬프트가 다시 표시됩니다.ADFS 3.0, ADAL, Web API 및 Xamarin으로 토큰 새로 고침

우리가 읽은 바에 따르면 매 통화마다 AcquireTokenAsync를 사용하고 ADAL이 토큰/새로 고침 토큰을 처리하도록되어 있습니다.

ADAL이 새로 고침 토큰을 사용하여 새 토큰을 얻으려고 할 때 서버에서 발생하는 오류입니다. 우리는 그 오류를 찾으려고했지만 많은 것을 찾지 못했습니다.

OAuth 토큰 요청 중 오류가 발생했습니다.

추가 데이터

예외 정보 : Microsoft.IdentityServer.Web.Protocols.OAuth.Exceptions.OAuthInvalidScopeException : MSIS9330 :받은 OAuth 액세스 토큰 요청이 유효하지 않습니다. 'scope'매개 변수가 요청에 수신되었으며 AD FS에서 어떤 범위도 지원하지 않습니다 ( ). 받은 범위 : 'openid'. Microsoft.IdentityServer.Web.Protocols.OAuth.OAuthToken.OAuthRefreshTokenRequestContext.Validate()

에서 우리는 뭔가를 놓치고 있습니까? 범위를 설정하는 방법이 있습니까? 아니면 현재 사용중인 버전에서만 작동하지 않습니까? ADAL은 ADFS 서버에 대한 범위를 가진 게시물을 만듭니다.

우리는 Azure AD를 사용하지 않습니다!

iOS 앱의 뷰 컨트롤러에서 전화 : 웹 API에

PlatformParameters p = new PlatformParameters(this); 

AuthenticationContext authContext = new AuthenticationContext("https://adfs.domain.com/adfs", false); 

AuthenticationResult _authResult = await authContext.AcquireTokenAsync("https://webapi.domain.com", "E1CF1107-FF90-4228-93BF-26052DD2C714", “http://anarbitraryreturnuri/”, p); 

Startup.Auth.cs : 여기

public void ConfigureAuth(IAppBuilder app) 
     { 
      app.UseActiveDirectoryFederationServicesBearerAuthentication(
       new ActiveDirectoryFederationServicesBearerAuthenticationOptions 
       { 
        MetadataEndpoint = ConfigurationManager.AppSettings["ida:AdfsMetadataEndpoint"], 
        TokenValidationParameters = new TokenValidationParameters() 
        { 
         ValidAudience = ConfigurationManager.AppSettings["ida:Audience"], 
        }, 
       } 
     } 

우리가 가지고있는 조각은 다음과 같습니다

  • ADFS 3.0이 설치된 Windows Server 2012 R2 (온 프레미스)
  • SsoLifetime = 60
  • TokenLifetime (신뢰 당사자) = 10
  • ADAL 3.13.8
  • .NET 웹 API
  • 자 마린 iOS 앱

여기에 우리가 얻을하는 데 사용되는 게시물의 일부입니다 작업 :

http://www.cloudidentity.com/blog/2013/10/25/securing-a-web-api-with-adfs-on-ws2012-r2-got-even-easier/

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

답변

1

문제는 ADAL 소스 코드에 있습니다. 서버 로그의 오류는 매우 구체적입니다.

'범위'매개 변수가 요청에 수신되었으며 AD FS에서 범위를 지원하지 않습니다.수신 범위 : 'openid'. ADAL 라이브러리는 새로 고침 토큰을 가져올 때 범위 매개 변수를 보냅니다. ADFS 3.0은 openid 범위를 지원하지 않으므로 실패합니다.

는 GitHub의에서 ADAL 코드를 다운로드 - https://github.com/AzureAD/azure-activedirectory-library-for-dotnet

열기 AcquireTokenHandlerBase.cs 여기에 있습니다 :

protected async Task<AuthenticationResultEx> SendTokenRequestByRefreshTokenAsync(string refreshToken) 
    { 
     var requestParameters = new DictionaryRequestParameters(this.Resource, this.ClientKey); 
     requestParameters[OAuthParameter.GrantType] = OAuthGrantType.RefreshToken; 
     requestParameters[OAuthParameter.RefreshToken] = refreshToken; 
     //requestParameters[OAuthParameter.Scope] = OAuthValue.ScopeOpenId; **This line causes refresh to fail** 

     AuthenticationResultEx result = await this.SendHttpMessageAsync(requestParameters).ConfigureAwait(false); 

     if (result.RefreshToken == null) 
     { 
      result.RefreshToken = refreshToken; 
      PlatformPlugin.Logger.Verbose(this.CallState, 
       "Refresh token was missing from the token refresh response, so the refresh token in the request is returned instead"); 
     } 

     return result; 
    } 

깨끗하고 :

enter image description here

가 SendTokenRequestByRefreshTokenAsync 호출에서 범위를 제거 프로젝트를 재건하십시오. 너겟 참조를 새 DLL로 바꿉니다. Xamarin iOS 프로젝트에 플랫폼 DLL을 포함하십시오. ADAL 새로 고침을 얻기 위해 시도 이제

enter image description here

는 성공한다 토큰.

enter image description here