본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

OAuth 2.0 Introspection 플러그인

원문 보기 위키 갱신

OAuth 2.0 Introspection 플러그인 (OAuth 2.0 Introspection Plugin)

이 플러그인은 제3자 OAuth 2.0 인증 서버의 인트로스펙션 엔드포인트를 사용해 액세스 토큰을 검증해요. Kong Gateway가 클라이언트의 토큰을 확인하고, 유효한 경우 업스트림 서비스로 요청을 전달해요. 또한 인트로스펙션 응답을 Consumer와 연결하고, 요청에 다양한 헤더를 추가해요. 더 많은 기능이 필요하면 OpenID Connect 플러그인도 고려해볼 수 있어요.

출처: 문서

본문

인증 서버가 자체 introspection 엔드포인트(RFC 7662)를 활용하는 방식이에요. 이 플러그인은 Consumer가 이미 타사 OAuth 2.0 서버에서 검증될 액세스 토큰을 가지고 있다고 가정해요.

참고: OpenID Connect Plugin은 OAuth 2.0 토큰 인트로스펙션도 지원하며, 이 플러그인보다 더 많은 기능(예: 범위별 액세스 제한)을 제공해요.

OAuth 2.0 Introspection 작동 방식

  1. 클라이언트가 타사 OAuth 2.0 서버를 사용해 액세스 토큰을 생성하고, 그 토큰을 사용해 Kong Gateway를 통해 요청을 보내요.
  2. 타사 OAuth 2.0 서버가 OAuth 2.0 Introspection 플러그인을 활용해 클라이언트의 액세스 토큰을 검증해요.
  3. 토큰이 유효하면 Kong Gateway가 요청을 업스트림 서비스로 프록시하고, 업스트림 서비스는 Kong Gateway를 통해 클라이언트에 응답을 보내요.
 
sequenceDiagram
    autonumber
    participant client as Client
    participant oauth as OAuth 2.0 server
    participant kong as Kong Gateway with 
Introspection plugin participant upstream as Upstream service activate client activate oauth client->>oauth: request access token oauth->>client: generate access token activate kong client->>kong: send request with
access token deactivate client kong->>oauth: send access token
for verification oauth->>kong: verify access token activate upstream kong->>upstream: send request with
access token upstream->>kong: response deactivate upstream activate client kong->>client: response deactivate kong deactivate client

응답을 Consumer와 연결하기

인트로스펙션 응답 해석을 Kong Gateway Consumer와 연결하려면, 인트로스펙션 엔드포인트 응답에서 반환된 것과 동일한 username으로 Consumer를 프로비저닝하세요.

업스트림 헤더

클라이언트가 인증되면 플러그인은 요청을 업스트림 API/마이크로서비스로 프록시하기 전에 다음 헤더를 요청에 추가해요. 이 헤더들을 사용해 코드에서 Consumer를 식별하세요:

  • X-Consumer-ID, Kong Gateway에서 Consumer의 ID (일치하는 경우)
  • X-Consumer-Custom-ID, Consumer의 custom_id (일치하고 존재하는 경우)
  • X-Consumer-Username, Consumer의 username (일치하고 존재하는 경우)
  • X-Anonymous-Consumer, 인증에 실패하고 대신 anonymous Consumer가 설정된 경우 true로 설정됨.
  • X-Credential-Scope, Introspection 응답에서 반환된 값 (있는 경우)
  • X-Credential-Client-ID, Introspection 응답에서 반환된 값 (있는 경우)
  • X-Credential-Identifier, Introspection 응답에서 반환된 값 (있는 경우)
  • X-Credential-Token-Type, Introspection 응답에서 반환된 값 (있는 경우)
  • X-Credential-Exp, Introspection 응답에서 반환된 값 (있는 경우)
  • X-Credential-Iat, Introspection 응답에서 반환된 값 (있는 경우)
  • X-Credential-Nbf, Introspection 응답에서 반환된 값 (있는 경우)
  • X-Credential-Sub, Introspection 응답에서 반환된 값 (있는 경우)
  • X-Credential-Aud, Introspection 응답에서 반환된 값 (있는 경우)
  • X-Credential-Iss, Introspection 응답에서 반환된 값 (있는 경우)
  • X-Credential-Jti, Introspection 응답에서 반환된 값 (있는 경우)

또한 config.custom_claims_forward에 지정된 모든 클레임도 X-Credential- 접두사와 함께 전달돼요.

참고: 인증에 실패하면 플러그인은 X-Credential-* 헤더를 설정하지 않아요. 대신 X-Anonymous-Consumer: true를 추가하고 anonymous Consumer를 설정해요.

관련 자료

더 알아보기 (Learn more)