2017-01-04 6 views
1

이 질문은 실제로 this 내 질문에 대한 연속적인 질문입니다. 인증 코드 흐름을 사용하여 Identityserver4에서 access_token 및 id_token을 가져 오려고합니다.IdentityServer4의 인증 엔드 포인트에서 access_token, id_token을 얻는 방법은 무엇입니까?

그러나 "인증"엔드 포인트에 액세스하려고하면 HTTP 오류 405 (허용되지 않음)가 발생합니다.

HTTP GET 요청

http://localhost:2000/connect/authorize? 
client_id=client 
&client_secret=secret 
&grant_type=authorization_code 
&username=admin 
&password=admin 
&response_type=id_token+token 
&scope=openid+profile+offline_access 

클라이언트 :

new Client 
{ 
    ClientId = "client", 
    ClientSecrets = { new Secret("secret".Sha256())},     
    AllowedGrantTypes = new List<string> { "authorization_code" }, 
    AccessTokenType = AccessTokenType.Jwt, 
    AllowedScopes = { StandardScopes.OpenId.Name, "api1" } 
} 

사용자 :

new InMemoryUser 
    { 
    Subject = "1", 
    Username = "admin", 
    Password = "admin" 
    } 

내 질문은, 어떻게 access_token이 얻을 id_token하는 엔드 포인트에 권한을 부여 호출하려면? 내 "클라이언트"및 "사용자"구성의 문제점은 무엇입니까?

+1

로깅을 사용하셨습니까? 그러면 많은 구성 문제를 발견하는 데 도움이됩니다. –

답변

1

두 아이디어 :

  1. 는 HTTP 405 오류는 웹 브라우저의 same origin policy 때문일 수 있습니다. 하지만 클라이언트는 브라우저 기반 클라이언트가 아닌 기밀 클라이언트처럼 보입니다. 이는 사용자가 실수로 웹 브라우저를 통해 요청하지 않는 한 동일한 원본 정책이 적용되지 않음을 의미합니다.

  2. 허용되지 않는 HTTP 동사를 사용하면 HTTP 405 오류가 발생할 수도 있습니다. 예를 들어 URL에 GET 만 허용되는 경우 POST을 사용하는 경우 GET 요청을 100 % 확인하십시오.

1

몇 가지 문제가 있습니다. 여러 흐름을 혼합하고 있습니다.

1) 승인 엔드 포인트 (토큰 엔드 포인트가 아닌)에서 id_token을 다시 받으려면 하이브리드 플로우 ... 인증 코드 플로우가 필요하지 않습니다. here을 참조하십시오. 따라서 응답 유형을 적절하게 변경해야합니다. 클라이언트가 SPA 인 경우 암시 적 플로우를 사용할 수 있으며 엔드 포인트 권한 부여 (인증 코드 플로우가 아님)에서 id_tokenaccess_token을 얻을 수 있습니다.

2) client_secret은 권한 부여 엔드 포인트에 대한 매개 변수가 아닙니다. 어느 쪽도 grant_type입니다. 유효한 매개 변수는 here을 참조하십시오.

3) 어떠한 경우에도 Authorize 끝점에 사용자 이름과 암호를 보내지 마십시오. 리소스 소유자 흐름을 사용하는 경우 토큰 끝점으로 보내지 만 승인하지 마십시오. 유효한 매개 변수에 대한 설명과 함께 위의 링크를 참조하십시오.

그래서 당신은 하이브리드 흐름으로 전환하고 여기에 코드를 변경할 수 있습니다 :이 호출의 응답이 id_tokenaccess_token 포함됩니다

http://localhost:2000/connect/authorize? 
client_id=client 
&redirect_uri=<add redirect uri> 
&response_type=code+id_token+token 
&scope=openid+profile+api1 
&state=... 

.

new Client 
{ 
    ClientId = "client", 
    ClientName = "Your Client", 
    AllowedGrantTypes = GrantTypes.Hybrid, 

    ClientSecrets = 
    { 
     new Secret("secret".Sha256()) 
    }, 

     RedirectUris   = { "<add redirect uri>" }, 
     PostLogoutRedirectUris = { "<add post logout redirect uri>" }, 

    AllowedScopes = 
    { 
     IdentityServerConstants.StandardScopes.OpenId, 
     IdentityServerConstants.StandardScopes.Profile, 
     "api1" 
    } 
}; 
+0

https : // stackoverflow.com/questions/47979716/how-to-call-authorize-endpoint-without-login-prompt-in-gluu -이 옵션은 무엇입니까? –

관련 문제