OAuth 2.0
Authrimは最新のセキュリティベストプラクティスに従ったOAuth 2.0を実装しており、OAuth 2.1の推奨事項もサポートしています。
概要
- 標準: RFC 6749、RFC 6750
- OAuth 2.1: OAuth 2.1ドラフトに準拠
- セキュリティ: OAuth Security BCPに従う
対応グラントタイプ
認可コードグラント
すべてのクライアントに推奨されるグラント:
POST /token HTTP/1.1Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=auth_code_value&redirect_uri=https://app.example.com/callback&client_id=client_id&code_verifier=pkce_verifierリフレッシュトークングラント
リフレッシュトークンを新しいトークンと交換:
POST /token HTTP/1.1Content-Type: application/x-www-form-urlencodedAuthorization: Basic <base64(client_id:client_secret)>
grant_type=refresh_token&refresh_token=refresh_token_valueクライアントクレデンシャルグラント
マシン間認証用:
POST /token HTTP/1.1Content-Type: application/x-www-form-urlencodedAuthorization: Basic <base64(client_id:client_secret)>
grant_type=client_credentials&scope=api.read api.writeデバイス認可グラント
入力制約のあるデバイス用(デバイスフローを参照):
POST /token HTTP/1.1Content-Type: application/x-www-form-urlencoded
grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=device_code_value&client_id=client_idJWTベアラーグラント
信頼されたアサーション発行者との識別連携用:
POST /token HTTP/1.1Content-Type: application/x-www-form-urlencoded
grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=jwt_assertion&client_id=client_idエンドポイント
| エンドポイント | メソッド | 説明 |
|---|---|---|
/authorize | GET/POST | 認可エンドポイント |
/token | POST | トークンエンドポイント |
/revoke | POST | トークン失効 |
/introspect | POST | トークンイントロスペクション |
トークンタイプ
アクセストークン
以下を含むJWT形式のアクセストークン:
{ "iss": "https://auth.example.com", "sub": "user-id-123", "aud": "https://api.example.com", "exp": 1699880000, "iat": 1699876400, "jti": "unique-token-id", "scope": "read write", "client_id": "my_client_id"}リフレッシュトークン
新しいアクセストークンを取得するための長寿命トークン:
- ローテーション: リフレッシュトークンは使用ごとにローテーション
- 有効期限: 設定可能な有効期間(デフォルト:30日)
- 失効:
/revokeエンドポイントで失効可能
クライアント認証
client_secret_basic
クライアント資格情報によるHTTP Basic認証:
Authorization: Basic <base64(client_id:client_secret)>client_secret_post
リクエストボディでクライアント資格情報を送信:
POST /tokenContent-Type: application/x-www-form-urlencoded
client_id=my_client_id&client_secret=my_client_secret&grant_type=...private_key_jwt
クライアントの秘密鍵で署名されたJWTクライアントアサーション:
POST /tokenContent-Type: application/x-www-form-urlencoded
client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_assertion=eyJhbGciOiJSUzI1NiJ9...&grant_type=...none
パブリッククライアント用(PKCEが必須):
POST /tokenContent-Type: application/x-www-form-urlencoded
client_id=public_client_id&grant_type=authorization_code&code=...&code_verifier=...トークンイントロスペクション
トークンがアクティブかどうかを確認し、メタデータを取得:
POST /introspect HTTP/1.1Content-Type: application/x-www-form-urlencodedAuthorization: Basic <base64(client_id:client_secret)>
token=access_token_value&token_type_hint=access_tokenレスポンス:
{ "active": true, "scope": "read write", "client_id": "my_client_id", "token_type": "Bearer", "exp": 1699880000, "iat": 1699876400, "sub": "user-id-123", "aud": "https://api.example.com", "iss": "https://auth.example.com"}トークン失効
アクセストークンまたはリフレッシュトークンを失効:
POST /revoke HTTP/1.1Content-Type: application/x-www-form-urlencodedAuthorization: Basic <base64(client_id:client_secret)>
token=token_value&token_type_hint=refresh_tokenレスポンス: 200 OK(RFC 7009に従い常に返す)
レスポンスモード
query(codeのデフォルト)
クエリ文字列に認可コード:
https://app.example.com/callback?code=abc123&state=xyzfragment(implicitのデフォルト)
URLフラグメントにトークン:
https://app.example.com/callback#access_token=abc123&token_type=Bearerform_post
POSTで認可レスポンスを送信:
<form method="post" action="https://app.example.com/callback"> <input type="hidden" name="code" value="abc123"> <input type="hidden" name="state" value="xyz"></form>エラーレスポンス
標準的なOAuth 2.0エラー形式:
{ "error": "invalid_request", "error_description": "リクエストに必須パラメータがありません"}エラーコード:
| エラー | 説明 |
|---|---|
invalid_request | パラメータが不足または無効 |
unauthorized_client | クライアントがグラントタイプに対して認可されていない |
access_denied | ユーザーが認可を拒否 |
unsupported_response_type | レスポンスタイプがサポートされていない |
invalid_scope | リクエストされたスコープが無効 |
server_error | サーバーでエラーが発生 |
temporarily_unavailable | サーバーが一時的に利用不可 |
invalid_client | クライアント認証に失敗 |
invalid_grant | グラントが無効または期限切れ |
unsupported_grant_type | グラントタイプがサポートされていない |
OAuth 2.1準拠
AuthrimはOAuth 2.1の推奨事項に従います:
- PKCEが必須 - 認可コードフローに対して
- リフレッシュトークンローテーション - デフォルトで有効
- インプリシットグラントなし - 新規アプリケーションに対して
- パスワードグラントなし - 削除済み
- 完全一致リダイレクトURI - 正確なマッチングのみ
セキュリティベストプラクティス
- PKCEを使用 - すべての認可コードフローに必須
- stateパラメータを使用 - CSRF攻撃を防止
- リダイレクトURIを検証 - 完全一致のみ
- 短寿命アクセストークンを使用 - 1時間以下
- リフレッシュトークンをローテーション - 使い捨て
- トークンバインディングを実装 - 高セキュリティにはDPoPを検討