OpenID Connect (OIDC)
AuthrimはOpenID Connect Core 1.0に完全準拠しており、アプリケーションに安全な認証を提供します。
概要
- 標準: OpenID Connect Core 1.0
- 適合性: OpenID認定適合性テストスイート対応
- ディスカバリー: 完全なOIDCディスカバリーサポート
対応フロー
認可コードフロー + PKCE(推奨)
すべてのクライアントタイプに最も安全なフロー:
クライアント → 認可エンドポイント → ユーザーログイン → 認可コードクライアント → トークンエンドポイント (+ PKCE) → アクセストークン + IDトークンハイブリッドフロー
即時のID検証とバックエンドトークン交換の両方が必要なアプリケーション向け:
code id_tokencode tokencode id_token token
インプリシットフロー
レガシーアプリケーション専用(新規実装には非推奨):
id_tokenid_token token
ディスカバリーエンドポイント
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", "scopes_supported": ["openid", "profile", "email", "address", "phone", "offline_access"], "response_types_supported": ["code", "id_token", "id_token token", "code id_token", "code token", "code id_token token"], "response_modes_supported": ["query", "fragment", "form_post"], "grant_types_supported": ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code"], "subject_types_supported": ["public", "pairwise"], "id_token_signing_alg_values_supported": ["RS256", "ES256"], "token_endpoint_auth_methods_supported": ["client_secret_basic", "client_secret_post", "private_key_jwt"], "code_challenge_methods_supported": ["S256"]}JWKSエンドポイント
IDトークン検証用のJSON Web Key Setを取得:
GET /.well-known/jwks.jsonレスポンス:
{ "keys": [ { "kty": "RSA", "kid": "key-id-1", "use": "sig", "alg": "RS256", "n": "...", "e": "AQAB" } ]}認可フロー
1. 認可リクエスト
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=S256Host: auth.example.comパラメータ:
| パラメータ | 必須 | 説明 |
|---|---|---|
response_type | はい | 認可コードフローの場合はcode |
client_id | はい | クライアント識別子 |
redirect_uri | はい | 登録済みリダイレクトURI |
scope | はい | openidを含む必要あり |
state | 推奨 | CSRF保護 |
nonce | OIDC必須 | IDトークンバインディング |
code_challenge | 推奨 | PKCEコードチャレンジ |
code_challenge_method | 推奨 | S256である必要あり |
2. ユーザー認証
ユーザーはログインページにリダイレクトされ、認証を行います。
3. 認可レスポンス
HTTP/1.1 302 FoundLocation: https://myapp.example.com/callback ?code=authorization_code_value &state=random_state_value4. トークンリクエスト
POST /token HTTP/1.1Content-Type: application/x-www-form-urlencodedAuthorization: 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_verifier5. トークンレスポンス
{ "access_token": "eyJhbGciOiJSUzI1NiJ9...", "token_type": "Bearer", "expires_in": 3600, "id_token": "eyJhbGciOiJSUzI1NiJ9...", "refresh_token": "eyJhbGciOiJSUzI1NiJ9...", "scope": "openid profile email"}IDトークン
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_verified": true}標準クレーム
| クレーム | 説明 |
|---|---|
iss | 発行者識別子 |
sub | サブジェクト識別子(ユーザーID) |
aud | オーディエンス(クライアントID) |
exp | 有効期限 |
iat | 発行時刻 |
nonce | 認可リクエストからのnonce |
auth_time | 認証時刻 |
acr | 認証コンテキストクラス参照 |
amr | 認証方法参照 |
at_hash | アクセストークンハッシュ |
c_hash | コードハッシュ(ハイブリッドフロー) |
プロファイルスコープクレーム
| クレーム | 説明 |
|---|---|
name | フルネーム |
given_name | 名 |
family_name | 姓 |
nickname | ニックネーム |
preferred_username | 優先ユーザー名 |
picture | プロファイル画像URL |
locale | ロケール |
zoneinfo | タイムゾーン |
updated_at | 最終更新時刻 |
メールスコープクレーム
| クレーム | 説明 |
|---|---|
email | メールアドレス |
email_verified | メール検証状態 |
UserInfoエンドポイント
ユーザープロファイル情報を取得:
GET /userinfo HTTP/1.1Authorization: Bearer <access_token>レスポンス:
{ "sub": "user-id-123", "name": "John Doe", "given_name": "John", "family_name": "Doe", "email_verified": true, "picture": "https://example.com/photo.jpg"}クライアント登録
動的クライアント登録
POST /register HTTP/1.1Content-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"]}スコープ
| スコープ | 説明 |
|---|---|
openid | OIDC必須、subクレームを返す |
profile | プロファイルクレームを返す(name、picture等) |
email | emailとemail_verifiedクレームを返す |
address | addressクレームを返す |
phone | phone_numberとphone_number_verifiedを返す |
offline_access | リフレッシュトークンを返す |
セキュリティベストプラクティス
- 常にPKCEを使用 - 認可コードの傍受を防止
- stateパラメータを使用 - CSRF攻撃を防止
- nonceパラメータを使用 - IDトークンのリプレイを防止
- IDトークンを検証 - 署名、発行者、オーディエンス、有効期限を検証
- 短寿命トークンを使用 - トークン盗難の影響を最小化
- 適切なログアウトを実装 - ログアウト時にトークンを失効