2017-01-22 3 views
1

IdentityServer3에서 작동하는 토큰 URL에 액세스하려고합니다.IdentityServer3, 암시 적 플로우, 토큰을 얻는 방법?

var options = new IdentityServerOptions 
     { 
      LoggingOptions = new LoggingOptions 
      { 
       WebApiDiagnosticsIsVerbose = true, 
       EnableWebApiDiagnostics = true, 
       EnableHttpLogging = true, 
       EnableKatanaLogging= true 
      }, 
      Factory = new IdentityServerServiceFactory() 
       .UseInMemoryClients(Clients.Get()) 
       .UseInMemoryScopes(Scopes.Get()) 
       .UseInMemoryUsers(Users.Get()), 
      RequireSsl = false, 
      EnableWelcomePage = false, 

     }; 

     app.UseIdentityServer(options); 

는 클라이언트 구성 :

new Client 
      { 
       Enabled = true, 
       ClientName = "JS Client", 
       ClientId = "js", 
       Flow = Flows.Implicit, 
       RedirectUris = new List<string> 
       { 
        "http://localhost:56522" 
       }, 
       AllowedCorsOrigins = new List<string> 
       { 
        "http://localhost:56522" 
       }, 
       AllowAccessToAllScopes = true 
      } 

엔드 포인트 토큰 다음 HTTP 요청을 POST 시도 : 서버는 다음과 같은 방법으로 구성되어

Content-Type:application/x-www-form-urlencoded 
grant_type:password 
redirect_uri:http://localhost:56522 
client_id:js 
username:bob 
password:secret 
scope:api 

내가 잘못된 클라이언트를 얻기를 오류 메시지 및 로그 표시 : 조치가 'IdentityServer3.Core.Results.Tok enErrorResult '', Operation = ReflectedHttpActionDescriptor.ExecuteAsync

어떤 아이디어가 여전히 누락 되었습니까?

+1

IdentityServer에 대한 GET 요청을 생성하고 토큰을 얻으려고 시도 할 수 있습니다.이 요청을 시도해보십시오 : '/ connect/authorize? client_id = js & redirect_uri = http : // localhost : 56522 & response_type = token & scope = api & state = ef969376c1d34ccaa03f8cd449c96bd7' 보호를위한 가치 - 클라이언트에서 비교) js 클라이언트의 경우이 라이브러리를 사용할 수 있습니다 (https://github.com/IdentityModel/oidc-client-js). – Jenan

답변

2

귀하의 요청은 OAuth Resource Owner (OAuth 리소스 소유자) 플로우 인 password 보조금 유형을 사용하고 있지만 클라이언트는 OpenID Connect Implicit 흐름을 사용하도록 구성되어 있습니다.

리소스 소유자 흐름을 사용하도록 클라이언트 구성을 변경하거나 요청을 유효한 OpenID Connect 요청으로 변경하십시오.

예 : GET /connect/authorize?client_id=js&scope=openid api&response_type=id_token token&redirect_uri=http://localhost:56522&state=abc&nonce=xyz. 그러면 로그인 페이지로 이동합니다.

또는 @ Yenan과 같은 JavaScipt 라이브러리 (예 : IdentityModel oidc-client)를 사용하여 이러한 요청을 처리 할 수 ​​있습니다.