grant_type : authorization_code를 사용할 때 Identity Server 4 / connect / token이 400 잘못된 요청을 반환 함

라비

Identity Server 4 앱을 설정했습니다. 각도 클라이언트 앱을 설정하려고합니다. 앵귤러 앱이 /connect/tokenapi를 호출하면 400 개의 Bad Request를 받으면 Authorization 코드를받은 후 Provider 로그인 페이지에 접속하여 성공적으로 로그인 할 수 있습니다 . Postman으로 테스트했으며 사용할 때 작동합니다.

grant_type:client_credentials

정보

https : // localhost : 5001 / connect / token

grant_type:authorization_code
client_id:angular_app_client_id
code_verifier:C0.731426161751518815973254dfd6715973254680670.9347059398232558
code:oSEydAywPs_zg4MRwbqwH-ly8ToWdrtexTDgx0ee7eY
redirect_uri:http://localhost:4200/callback
client_secret:<secret>
require_pkce:false
requried_client_secret:false

각도 앱의 OpenIdConfiguration

const openIdConfiguration: OpenIdConfiguration = {
    stsServer: this.authUrl,
    redirect_url: this.originUrl + 'callback',
    client_id: 'demo_client_id',
    response_type: 'code',
    scope: 'openid profile',
    post_logout_redirect_uri: this.originUrl,
    forbidden_route: '/forbidden',
    unauthorized_route: '/unauthorized',
    silent_renew: true,
    silent_renew_url: this.originUrl + '/silent-renew.html',
    history_cleanup_off: true,
    auto_userinfo: true,
    log_console_warning_active: true,
    log_console_debug_active: true,
    max_id_token_iat_offset_allowed_in_seconds: 10,
};

우편 배달부 요청 여기에 이미지 설명 입력

서버 로그

{"ClientId": "angular_app_client_id", "Category": "Authentication", "Name": "Client Authentication Failure", "EventType": "Failure", "Id": 1011, "Message": "Invalid client secret", "ActivityId": "0HM1VK1OS0MDK:00000001", "TimeStamp": "2020-08-13T16:29:52.0000000Z", "ProcessId": 2002, "LocalIpAddress": "::1:5001", "RemoteIpAddress": "::1", "$type": "ClientAuthenticationFailureEvent"}

grant_type이 client_credentials 여기에 이미지 설명 입력

도와주세요...

Nahidf
  • 앵귤러 클라이언트 앱은 대화 형 앱이므로 RequireClientSecretfalse 로 설정해야 합니다.
  • client_secret클라이언트 앱 및 IdentityServer에 대한 모든 호출에서 제거
  • 또한 대화 형 앱에 클라이언트 권한 부여가 아닌 코드 부여를 사용해야합니다.
    • 이 변경 후 DB의 클라이언트 구성은 다음과 같습니다.
client_id = angular_app_client_id, client_name = Angular App, grant_type = authorization_code
  • 비밀을 제거했으며이 client_credentials보조금은 스파 앱에 사용되지 않습니다.

  • RequirePkce클라이언트 구성에서 ( ) [https://github.com/IdentityServer/IdentityServer4/blob/main/src/EntityFramework.Storage/src/Entities/Client.cs#L29]를 true로 설정-DB의 경우

  • response_type: "code"js 클라이언트에서 설정

    • 다음은 ur js 클라이언트 코드가 어떻게 보이는지에 대한 예입니다.
var config = {
    authority: "http://localhost:5000",
    client_id: "jsclient",
    redirect_uri: "http://localhost:5003/callback.html",
    response_type: "code",
    scope:"openid profile",
    post_logout_redirect_uri : "http://localhost:5003/index.html",
};
  • 또한 AllowedCorsOriginsSPA 앱이 앱 URL 이되도록 설정해야합니다 . 이것은 브라우저에서 호출되는 원인입니다.

나는 전체 작업 예제가 여기에 확인해 주시기 바랍니다

여기에서 대화 형 앱을 설정하는 방법에 대해 자세히 알아보세요.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관