コンテンツにスキップ

OpenID Connect (OIDC)

AuthrimはOpenID Connect Core 1.0に完全準拠しており、アプリケーションに安全な認証を提供します。

  • 標準: OpenID Connect Core 1.0
  • 適合性: OpenID認定適合性テストスイート対応
  • ディスカバリー: 完全なOIDCディスカバリーサポート

認可コードフロー + PKCE(推奨)

Section titled “認可コードフロー + PKCE(推奨)”

すべてのクライアントタイプに最も安全なフロー:

クライアント → 認可エンドポイント → ユーザーログイン → 認可コード
クライアント → トークンエンドポイント (+ PKCE) → アクセストークン + IDトークン

即時のID検証とバックエンドトークン交換の両方が必要なアプリケーション向け:

  • code id_token
  • code token
  • code id_token token

レガシーアプリケーション専用(新規実装には非推奨):

  • id_token
  • id_token token

ディスカバリーエンドポイント

Section titled “ディスカバリーエンドポイント”

OpenIDプロバイダー設定を取得:

GET /.well-known/openid-configuration

レスポンス:

{
"issuer": "https://auth.example.com",
"authorization_endpoint": "https://auth.example.com/authorize",
"token_endpoint": "https://auth.example.com/token",
"userinfo_endpoint": "https://auth.example.com/userinfo",
"jwks_uri": "https://auth.example.com/.well-known/jwks.json",
"registration_endpoint": "https://auth.example.com/register",
"introspection_endpoint": "https://auth.example.com/introspect",
"revocation_endpoint": "https://auth.example.com/revoke",
"pushed_authorization_request_endpoint": "https://auth.example.com/par",
"device_authorization_endpoint": "https://auth.example.com/device_authorization",
"scopes_supported": ["openid", "profile", "email", "address", "phone"],
"response_types_supported": ["code", "id_token", "id_token token", "code id_token", "code token", "code id_token token", "none"],
"response_modes_supported": ["query", "fragment", "form_post", "query.jwt", "fragment.jwt", "form_post.jwt", "jwt"],
"grant_types_supported": ["authorization_code", "refresh_token", "implicit", "urn:ietf:params:oauth:grant-type:jwt-bearer", "urn:ietf:params:oauth:grant-type:device_code", "urn:openid:params:grant-type:ciba", "urn:ietf:params:oauth:grant-type:token-exchange", "client_credentials"],
"subject_types_supported": ["public", "pairwise"],
"id_token_signing_alg_values_supported": ["RS256"],
"token_endpoint_auth_methods_supported": ["client_secret_basic", "client_secret_post", "client_secret_jwt", "private_key_jwt", "none"],
"code_challenge_methods_supported": ["S256"],
"dpop_signing_alg_values_supported": ["ES256", "RS256", "PS256", "EdDSA"],
"end_session_endpoint": "https://auth.example.com/logout"
}

grant type と async endpoint は tenant profile と feature flag によりフィルタされます。各 tenant での正確な対応範囲は production の discovery metadata を source of truth としてください。

IDトークン検証用のJSON Web Key Setを取得:

GET /.well-known/jwks.json

レスポンス:

{
"keys": [
{
"kty": "RSA",
"kid": "key-id-1",
"use": "sig",
"alg": "RS256",
"n": "...",
"e": "AQAB"
}
]
}
GET /authorize
?response_type=code
&client_id=my_client_id
&redirect_uri=https://myapp.example.com/callback
&scope=openid+profile+email
&state=random_state_value
&nonce=random_nonce_value
&code_challenge=...
&code_challenge_method=S256
Host: auth.example.com

パラメータ:

パラメータ必須説明
response_typeはい認可コードフローの場合はcode
client_idはいクライアント識別子
redirect_uriはい登録済みリダイレクトURI
scopeはいopenidを含む必要あり
state推奨CSRF保護
nonceOIDC必須IDトークンバインディング
code_challenge推奨PKCEコードチャレンジ
code_challenge_method推奨S256である必要あり

ユーザーはログインページにリダイレクトされ、認証を行います。

HTTP/1.1 302 Found
Location: https://myapp.example.com/callback
?code=authorization_code_value
&state=random_state_value
POST /token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: Basic <base64(client_id:client_secret)>
grant_type=authorization_code
&code=authorization_code_value
&redirect_uri=https://myapp.example.com/callback
&code_verifier=pkce_code_verifier
{
"access_token": "eyJhbGciOiJSUzI1NiJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"id_token": "eyJhbGciOiJSUzI1NiJ9...",
"refresh_token": "eyJhbGciOiJSUzI1NiJ9...",
"scope": "openid profile email"
}

IDトークンはユーザーIDクレームを含むJSON Web Token (JWT)です:

{
"iss": "https://auth.example.com",
"sub": "user-id-123",
"aud": "my_client_id",
"exp": 1699880000,
"iat": 1699876400,
"nonce": "random_nonce_value",
"auth_time": 1699876400,
"acr": "urn:mace:incommon:iap:silver",
"at_hash": "...",
"name": "John Doe",
"email": "john@example.com",
"email_verified": true
}
クレーム説明
iss発行者識別子
subサブジェクト識別子(ユーザーID)
audオーディエンス(クライアントID)
exp有効期限
iat発行時刻
nonce認可リクエストからのnonce
auth_time認証時刻
acr認証コンテキストクラス参照
amr認証方法参照
at_hashアクセストークンハッシュ
c_hashコードハッシュ(ハイブリッドフロー)

プロファイルスコープクレーム

Section titled “プロファイルスコープクレーム”
クレーム説明
nameフルネーム
given_name
family_name
nicknameニックネーム
preferred_username優先ユーザー名
pictureプロファイル画像URL
localeロケール
zoneinfoタイムゾーン
updated_at最終更新時刻
クレーム説明
emailメールアドレス
email_verifiedメール検証状態

ユーザープロファイル情報を取得:

GET /userinfo HTTP/1.1
Authorization: Bearer <access_token>

レスポンス:

{
"sub": "user-id-123",
"name": "John Doe",
"given_name": "John",
"family_name": "Doe",
"email": "john@example.com",
"email_verified": true,
"picture": "https://example.com/photo.jpg"
}
POST /register HTTP/1.1
Content-Type: application/json
{
"client_name": "My Application",
"redirect_uris": ["https://myapp.example.com/callback"],
"grant_types": ["authorization_code", "refresh_token"],
"response_types": ["code"],
"token_endpoint_auth_method": "client_secret_basic"
}

レスポンス:

{
"client_id": "generated_client_id",
"client_secret": "generated_client_secret",
"client_id_issued_at": 1699876400,
"client_secret_expires_at": 0,
"redirect_uris": ["https://myapp.example.com/callback"],
"grant_types": ["authorization_code", "refresh_token"],
"response_types": ["code"]
}
スコープ説明
openidOIDC必須、subクレームを返す
profileプロファイルクレームを返す(name、picture等)
emailemailとemail_verifiedクレームを返す
addressaddressクレームを返す
phonephone_numberとphone_number_verifiedを返す

refresh token の可用性は client metadata と tenant profile で制御されます。offline_access scope を前提にせず、discovery で公開される refresh_token grant を確認してください。

セキュリティベストプラクティス

Section titled “セキュリティベストプラクティス”
  1. 常にPKCEを使用 - 認可コードの傍受を防止
  2. stateパラメータを使用 - CSRF攻撃を防止
  3. nonceパラメータを使用 - IDトークンのリプレイを防止
  4. IDトークンを検証 - 署名、発行者、オーディエンス、有効期限を検証
  5. 短寿命トークンを使用 - トークン盗難の影響を最小化
  6. 適切なログアウトを実装 - ログアウト時にトークンを失効