OpenID Connect Dynamic Client Registration
OpenID Connect Dynamic Client Registration 1.0 定義了 Relying Party(RP)向 OpenID Provider(OP)動態註冊的標準機制。此規範是 RFC 7591(OAuth 2.0 Dynamic Client Registration) 的前身——RFC 7591 是在此基礎上泛化而來的。
解決什麼問題
Section titled “解決什麼問題”傳統的 Client 註冊流程需要開發者手動到 OP 的管理介面建立 Client、取得 client_id 與 client_secret。在以下場景會遇到困難:
- 跨組織 SSO 整合——RP 無法事先到每個 OP 手動註冊
- 大量 RP 需要自動化部署——例如多租戶 SaaS 環境中,每個租戶都需要獨立的 Client
- AI 工具整合——MCP(Model Context Protocol)讓 AI 應用程式連接不特定數量的 Server,手動註冊不切實際
Dynamic Client Registration 讓 RP 可以透過標準化的 API 自動完成註冊。
RP 向 OP 的 Registration Endpoint 發送 POST 請求,帶上 Client Metadata:
POST /register HTTP/1.1Host: op.example.comContent-Type: application/json
{ "application_type": "web", "redirect_uris": ["https://app.example.com/callback"], "client_name": "My Application", "logo_uri": "https://app.example.com/logo.png", "response_types": ["code"], "grant_types": ["authorization_code"], "token_endpoint_auth_method": "client_secret_basic", "id_token_signed_response_alg": "RS256"}Client Metadata
Section titled “Client Metadata”這些欄位在 RFC 7591 中也有定義,是通用的 OAuth 2.0 Client Metadata:
| 欄位 | 必要 | 說明 |
|---|---|---|
redirect_uris | REQUIRED | RP 的 Redirect URI 列表 |
response_types | OPTIONAL | RP 可使用的回應類型(如 code、id_token) |
grant_types | OPTIONAL | RP 可使用的授權模式(如 authorization_code) |
application_type | OPTIONAL | 應用程式類型,web 或 native,預設為 web |
client_name | OPTIONAL | RP 名稱,OP 會在授權頁面顯示給使用者 |
logo_uri | OPTIONAL | RP 的 Logo URI |
client_uri | OPTIONAL | RP 的首頁 URI |
contacts | OPTIONAL | RP 維護者的聯絡方式(email) |
token_endpoint_auth_method | OPTIONAL | Token Endpoint 的認證方式 |
scope | OPTIONAL | 請求的授權範圍 |
OIDC 特有欄位
Section titled “OIDC 特有欄位”這些欄位是 OIDC 獨有的,用來設定 ID Token、UserInfo 回應的簽章與加密方式:
| 欄位 | 說明 |
|---|---|
id_token_signed_response_alg | ID Token 的簽章演算法(如 RS256) |
id_token_encrypted_response_alg | ID Token 的加密演算法 |
id_token_encrypted_response_enc | ID Token 的內容加密演算法 |
userinfo_signed_response_alg | UserInfo 回應的簽章演算法 |
userinfo_encrypted_response_alg | UserInfo 回應的加密演算法 |
userinfo_encrypted_response_enc | UserInfo 回應的內容加密演算法 |
default_max_age | 預設的最大認證時間(秒) |
require_auth_time | 是否要求 ID Token 包含 auth_time |
default_acr_values | 預設的 Authentication Context Class Reference 值 |
這些欄位讓 RP 可以在註冊時就指定與 OP 之間的安全通訊方式,不需要另外協商。
OP 回傳新建立的 Client 資訊:
{ "client_id": "s6BhdRkqt3", "client_secret": "cf136dc3c1fc93f31185e5885805d", "client_id_issued_at": 1711929600, "client_secret_expires_at": 0, "redirect_uris": ["https://app.example.com/callback"], "client_name": "My Application", "response_types": ["code"], "grant_types": ["authorization_code"], "token_endpoint_auth_method": "client_secret_basic", "id_token_signed_response_alg": "RS256", "registration_access_token": "reg-token-abc123", "registration_client_uri": "https://op.example.com/register/s6BhdRkqt3"}| 欄位 | 說明 |
|---|---|
client_id | 新建立的 Client ID |
client_secret | Client Secret(僅 Confidential Client) |
client_id_issued_at | Client ID 核發時間(Unix timestamp) |
client_secret_expires_at | Client Secret 到期時間(0 代表不過期) |
registration_access_token | 用於後續讀取或更新 Client 設定的 Access Token |
registration_client_uri | 用於管理此 Client 註冊資訊的端點 |
其中 registration_access_token 和 registration_client_uri 是 OIDC DCR 特有的,讓 RP 註冊後可以再回來讀取或更新自己的設定。
Registration Endpoint 可以是開放註冊或需要認證:
- 開放註冊:任何人都可以註冊 RP,適合公開平台
- 需要 Initial Access Token:RP 必須持有預先取得的 Token 才能註冊,適合受控環境
POST /register HTTP/1.1Host: op.example.comAuthorization: Bearer INITIAL_ACCESS_TOKENContent-Type: application/json與 OAuth 2.0 DCR 的關係
Section titled “與 OAuth 2.0 DCR 的關係”OIDC Dynamic Client Registration 是原始規範,RFC 7591 是從它泛化而來的:
- OIDC DCR 定義了完整的註冊流程與 Client Metadata
- RFC 7591 抽取了通用的部分,使其適用於一般的 OAuth 2.0 場景
- 支援 OIDC 的 OP 通常同時相容兩種規範
如果你的場景涉及身分驗證(需要 ID Token),使用 OIDC DCR;如果只需要 OAuth 2.0 授權,RFC 7591 就足夠。