TIL

OAuth 2.0 Resource Server JWT

Minimal Dependencies for JWT

Minimal Configuration for JWTs

Specifying the Authorization Server

spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: https://idp.example.com/issuer

issuer-url 속성을 사용하려면 idp.example.com/issuer/.wellknown/openid-configuration, idp.example.com/.wellknown/openid-configuration/issuer 또는 idp.example.com/.wellknown/oauth-authorization-server/issuer 중 하나가 인증 서버에 지원되는 엔드포인트이어야 한다. 이 엔드포인트를 Provider Configuration 엔드포인트 또는 Authorization Server 메타데이터 엔드포인트라고 한다.

Startup Expectations

위 속성들과 종속성을 추가하면 리소스 서버는 자동적으로 JWT-encoded Bearer Token을 자체 설정한다.

  1. Provider Configuration 또는 Authorization Server 메타데이터를 jwks_url 속성을 통해 조회한다.
  2. 지원되는 알고리즘을 jwks_url을 통해 조회한다.
  3. 유효성 검사 전략을 구성하여 찾은 알고리즘의 유효 공개 키를 jwks_url로 조회한다.
  4. 유효성 검사 전략을 구성하여 idp.example.com에 대해 각 JWT 발급 클레임의 유효성을 검사한다.

Runtime Expectation

GET / HTTP/1.1
Authorization: Bearer some-token-value # Resource Server will process this
  1. jwks_url 엔드포인트에서 얻은 공개 키로 서명의 유효성을 검사하고 JWT와 일치하는지 확인한다.
  2. JWT를 검사하고 expnbf 타임스탬프, JWT의 iss 클레임 유효성을 검사한다.
  3. SCOPE_ prepix를 사용하여 권한을 확인한다.
    • 결과물인 Authentication#getPrincipal은 기본적으로 스프링 시큐리티 JWT 객체이다.

How JWT Authentication Works