Post

OIDC

OAuth 2.0 위에 구축된 인증 프로토콜인 OIDC(OpenID Connect)의 개념과 사용처 정리

개념 설명:

OpenID Connect 1.0 is a simple identity layer on top of the OAuth 2.0 protocol. It enables Clients to verify the identity of the End-User based on the authentication performed by an Authorization Server, as well as to obtain basic profile information about the End-User in an interoperable and REST-like manner.
공식문서
OpenID Connect 1.0은 OAuth 2.0 프로토콜 위에서 동작하며, 인증(authentication)과 사용자 정보를 안전하게 전달하는 ID 계층을 제공.

  • OIDC는 사용자가 누구인지(=ID)를 검증하는 “인증” 프로토콜
  • OAuth 2.0은 권한 위임(authorization)을 위한 프로토콜
  • OIDC는 OAuth의 Access Token 외에 ID Token(JWT 형식)을 추가로 발급

  • 비슷한 개념과 비교:
    • OAuth 2.0 vs OIDC
      • OAuth 2.0: 리소스에 접근할 권한만 부여
      • OIDC: 로그인 사용자 정보를 포함한 인증 수행 (ID Token 발급)
    • OIDC vs SAML
      • OIDC는 모바일 친화적, JSON 기반
      • SAML은 XML 기반, 주로 엔터프라이즈 환경에서 사용
  • 사용이 적합한 환경:
    • 소셜 로그인(Google, Apple 등)
    • 마이크로서비스 간 인증 처리
    • 싱글 사인온(SSO)
    • 모바일/SPA 환경에서 인증이 필요한 경우
  • 사용 방법:

    1. 기본 흐름

    • 사용자가 로그인 요청
    • Authorization Server (ex. Google)이 로그인 처리 후 Authorization Code 발급
    • 클라이언트가 Authorization Code로 Access Token, ID Token 요청
    • ID Token을 통해 사용자 인증 완료

    2. ID Token 예시 (JWT)

    1
    2
    3
    4
    5
    6
    7
    
    {
      "iss": "https://accounts.google.com",
      "sub": "1234567890",
      "aud": "client-id.apps.googleusercontent.com",
      "exp": 1714232345,
      "email": "enginrect@gmail.com"
    }
    

    3. 인기 라이브러리/툴

    • Keycloak, Auth0: OIDC 인증 서버 구현체
    • oidc-client-js, NextAuth.js: 클라이언트용 라이브러리

    4. 관련 커맨드/설정 예시

    • 예: curl로 OIDC 토큰 받기
      1
      2
      3
      4
      
      curl -X POST https://enginrect.com/oauth/token \
      -d "grant_type=authorization_code&code=abc123" \
      -d "client_id=your-client-id" \
      -d "client_secret=your-client-secret"
      
This post is licensed under CC BY 4.0 by the author.