クライアント認証
前提知識
このドキュメントを理解するには、以下の基礎知識が役立ちます:
- OAuth 2.0の基本 - OAuth 2.0の認可の仕組み
- トークンエンドポイント - トークン取得の流れ
概要
クライアント認証は、OAuth 2.0/OpenID Connectにおいてクライアント(アプリケーション)が認可サーバーに対して自身を証明するための仕組みです。
idp-serverは以下のクライアント認証方式をサポートしています:
| 認証方式 | 説明 | セキュリティレベル |
|---|---|---|
client_secret_basic | HTTP Basic認証 | 標準 |
client_secret_post | POSTボディにシークレット | 標準 |
client_secret_jwt | HMAC署名JWT | 高 |
private_key_jwt | 公開鍵署名JWT | 最高 |
tls_client_auth | mTLS証明書認証 | 最高 |
self_signed_tls_client_auth | 自己署名mTLS | 最高 |
none | 認証なし(Public Client) | - |
クライアント認証方式の詳細
client_secret_basic
HTTP Basic認証を使用してクライアントを認証します。
POST /tokens HTTP/1.1
Host: idp.example.com
Authorization: Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=xxx&redirect_uri=https://client.example.com/callback
Base64エンコード: client_id:client_secret
client_secret_post
リクエストボディにクライアントIDとシークレットを含めます。
POST /tokens HTTP/1.1
Host: idp.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&code=xxx
&redirect_uri=https://client.example.com/callback
&client_id=my_client
&client_secret=my_secret
client_secret_jwt
クライアントシークレットを使用してHMAC署名されたJWTで認証します。
POST /tokens HTTP/1.1
Host: idp.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&code=xxx
&redirect_uri=https://client.example.com/callback
&client_id=my_client
&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer
&client_assertion=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
JWTペイロードの例:
{
"iss": "my_client",
"sub": "my_client",
"aud": "https://idp.example.com",
"jti": "unique-token-id",
"exp": 1735300000,
"iat": 1735296400
}
private_key_jwt
クライアントの秘密鍵で署名されたJWTで認証します。最も安全な方式の一つです。
POST /tokens HTTP/1.1
Host: idp.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&code=xxx
&redirect_uri=https://client.example.com/callback
&client_id=my_client
&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer
&client_assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleTEifQ...
JWTペイロードはclient_secret_jwtと同様ですが、RSAまたはECDSA秘密鍵で署名されます。
RFC 7523: JWT Bearer Client Authentication
client_secret_jwtおよびprivate_key_jwtは、RFC 7523「JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants」に準拠しています。
Section 3: JWT Format and Processing Requirements
認可サーバーがJWTを受け入れるために、以下の要件を満たす必要があります:
署名要件
"The JWT MUST be digitally signed or have a Message Authentication Code (MAC) applied by the issuer."
— RFC 7523 Section 3
重要: alg: none(署名なし)のJWTは拒否されます。これはセキュリティ上の脆弱性を防ぐために必須です。