メインコンテンツまでスキップ

クライアント認証


前提知識

このドキュメントを理解するには、以下の基礎知識が役立ちます:


概要

クライアント認証は、OAuth 2.0/OpenID Connectにおいてクライアント(アプリケーション)が認可サーバーに対して自身を証明するための仕組みです。

idp-serverは以下のクライアント認証方式をサポートしています:

認証方式説明セキュリティレベル
client_secret_basicHTTP Basic認証標準
client_secret_postPOSTボディにシークレット標準
client_secret_jwtHMAC署名JWT
private_key_jwt公開鍵署名JWT最高
tls_client_authmTLS証明書認証最高
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は拒否されます。これはセキュリティ上の脆弱性を防ぐために必須です。

必須クレーム

クレーム説明RFC 7523の要件
iss発行者(= client_id)MUST - "The JWT MUST contain an 'iss' (issuer) claim that contains a unique identifier for the entity that issued the JWT."
sub主体(= client_id)MUST - "The JWT MUST contain a 'sub' (subject) claim identifying the principal that is the subject of the JWT."
aud対象者(= 認可サーバーURL)MUST - "The JWT MUST contain an 'aud' (audience) claim containing a value that identifies the authorization server as an intended audience."
exp有効期限MUST - "The JWT MUST contain an 'exp' (expiration time) claim that limits the time window during which the JWT can be used."
jtiJWT IDMAY - "The JWT MAY contain a 'jti' (JWT ID) claim that provides a unique identifier for the token."
iat発行時刻MAY - 推奨

aud(audience)クレームの値

audクレームには以下のいずれかを指定できます:

  1. 認可サーバーのIssuer URL - 例: https://idp.example.com
  2. トークンエンドポイントURL - 例: https://idp.example.com/tokens

"The token endpoint URL of the authorization server MAY be used as a value for the 'aud' element to identify the authorization server as an intended audience of the JWT."

— RFC 7523 Section 3

idp-serverの実装詳細

idp-serverでは、セキュリティ強化のため以下の追加要件があります:

クレームidp-server要件理由
jtiREQUIREDリプレイ攻撃防止

mTLS Client Authentication

tls_client_auth

PKI(Public Key Infrastructure)で発行された証明書を使用したmTLS認証です。

クライアント証明書のDNまたはSANが、事前に登録された値と一致する必要があります。

self_signed_tls_client_auth

自己署名証明書を使用したmTLS認証です。証明書のフィンガープリントまたは公開鍵が、事前に登録された値と一致する必要があります。


セキュリティ考慮事項

推奨事項

  1. Confidential Clientにはprivate_key_jwtまたはtls_client_authを推奨

    • クライアントシークレットの漏洩リスクがない
    • FAPI準拠に必要
  2. client_secret_basic/client_secret_postはFAPI非準拠

    • FAPI準拠が必要な場合は使用不可
    • 一般的なユースケースでは問題なし
  3. JWTの有効期限は短く設定

    • 推奨: 5分以内
    • 長すぎるとリプレイ攻撃のリスク増加

関連仕様


参考