OIDC / OAuth 2.0

ディスカバリドキュメント

OIDC

.well-known/openid-configuration によるOIDCプロバイダーの自動設定の仕組みを学びます。

ディスカバリドキュメントとは

OIDC ディスカバリドキュメントは、OIDCプロバイダーが公開するJSON形式のメタデータです。 以下のURLで取得できます。

GET https://accounts.example.com/.well-known/openid-configuration

このドキュメントを取得するだけで、クライアントはプロバイダーの 全エンドポイントURL、サポートされる機能、暗号化アルゴリズムなどを 自動的に知ることができます。

なぜ自動設定が重要か
  • 1.
    設定ミスの防止

    エンドポイントURLを手動で設定すると、タイプミスや古いURLの使用が起こりやすい。 ディスカバリなら常に最新の正しい設定を取得できる。

  • 2.
    プロバイダー切り替えの容易さ

    issuerのURLを変更するだけで、別のプロバイダーに切り替えられる。 個別のエンドポイントURLを調べ直す必要がない。

  • 3.
    機能サポートの自動検出

    PKCEのサポート有無、使用可能な署名アルゴリズム、 サポートされるスコープなどを自動的に判断できる。

  • 4.
    セキュリティの向上

    公開鍵 (JWKS) のURLも含まれるため、 トークン検証に必要な鍵を安全に取得できる。

主要なフィールド
issuer

プロバイダーの識別子URL

必須
authorization_endpoint

認可エンドポイントのURL

必須
token_endpoint

トークンエンドポイントのURL

必須
userinfo_endpoint

UserInfoエンドポイントのURL

推奨
jwks_uri

JSON Web Key Set (公開鍵) のURL

必須
registration_endpoint

動的クライアント登録エンドポイントのURL

推奨
scopes_supported

サポートされるスコープの一覧

推奨
response_types_supported

サポートされるresponse_type値 (例: "code", "id_token")

必須
grant_types_supported

サポートされるgrant_type値 (例: "authorization_code", "refresh_token")

推奨
subject_types_supported

サポートされるsubject識別子タイプ (例: "public", "pairwise")

必須
id_token_signing_alg_values_supported

IDトークンの署名に使用されるアルゴリズム (例: RS256)

必須
token_endpoint_auth_methods_supported

トークンエンドポイントの認証方法 (例: client_secret_basic)

推奨
claims_supported

サポートされるクレームの一覧

推奨
code_challenge_methods_supported

サポートされるPKCEメソッド (例: S256)

推奨
JSONサンプル
{
  "issuer": "https://accounts.example.com",
  "authorization_endpoint": "https://accounts.example.com/authorize",
  "token_endpoint": "https://accounts.example.com/token",
  "userinfo_endpoint": "https://accounts.example.com/userinfo",
  "jwks_uri": "https://accounts.example.com/.well-known/jwks.json",
  "registration_endpoint": "https://accounts.example.com/register",
  "scopes_supported": [
    "openid", "profile", "email", "address", "phone"
  ],
  "response_types_supported": [
    "code", "code id_token", "id_token"
  ],
  "grant_types_supported": [
    "authorization_code", "refresh_token"
  ],
  "subject_types_supported": ["public"],
  "id_token_signing_alg_values_supported": ["RS256"],
  "token_endpoint_auth_methods_supported": [
    "client_secret_basic", "client_secret_post"
  ],
  "claims_supported": [
    "sub", "iss", "aud", "exp", "iat",
    "name", "email", "email_verified", "picture"
  ],
  "code_challenge_methods_supported": ["S256"]
}
実際のプロバイダーのディスカバリURL

# Google

https://accounts.google.com/.well-known/openid-configuration

# Microsoft

https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration

# Auth0 (テナント名を置換)

https://{tenant}.auth0.com/.well-known/openid-configuration

次のステップ

次は UserInfoエンドポイント で、ユーザー情報を取得する仕組みを学びましょう。