OpenID Connect Discovery
OpenID Connect Discovery 1.0 定義了 Relying Party(RP)自動取得 OpenID Provider(OP)設定資訊的標準機制,於 2014 年發布。此規範是 RFC 8414(OAuth 2.0 Authorization Server Metadata) 的前身——RFC 8414 是在此基礎上泛化而來的。
解決什麼問題
Section titled “解決什麼問題”要串接一個 OP,RP 需要知道很多資訊:Authorization Endpoint 在哪裡、Token Endpoint 在哪裡、支援哪些 scope、用什麼演算法簽署 ID Token 等。如果每次串接都要手動查文件、寫死設定,會有幾個問題:
- 維護困難——OP 更新端點或設定時,所有 RP 都要跟著改
- 無法自動化——新的 RP 無法在執行期間自動取得串接資訊
- 容易出錯——手動設定容易遺漏或打錯
Discovery 讓 RP 只要知道 OP 的 Issuer URL,就能透過標準化的端點自動取得所有設定。
取得 Provider Metadata
Section titled “取得 Provider Metadata”RP 向 OP 的 well-known 端點發送 GET 請求:
GET /.well-known/openid-configuration HTTP/1.1Host: accounts.google.comOP 回傳一個 JSON 物件,稱為 OpenID Provider Metadata:
{ "issuer": "https://accounts.google.com", "authorization_endpoint": "https://accounts.google.com/o/oauth2/v2/auth", "token_endpoint": "https://oauth2.googleapis.com/token", "userinfo_endpoint": "https://openidconnect.googleapis.com/v1/userinfo", "jwks_uri": "https://www.googleapis.com/oauth2/v3/certs", "scopes_supported": ["openid", "profile", "email"], "response_types_supported": ["code", "id_token", "code id_token"], "grant_types_supported": ["authorization_code", "implicit"], "id_token_signing_alg_values_supported": ["RS256"]}OpenID Provider Metadata 欄位
Section titled “OpenID Provider Metadata 欄位”| 欄位 | 說明 |
|---|---|
issuer | OP 的識別 URL,與 ID Token 的 iss 值一致 |
authorization_endpoint | 啟動身分驗證的端點 |
jwks_uri | 驗證 ID Token 簽章用的公鑰端點(JWK Set) |
response_types_supported | 支援的 response_type 值 |
subject_types_supported | 支援的 Subject Identifier 類型(如 public、pairwise) |
id_token_signing_alg_values_supported | 支援的 ID Token 簽章演算法 |
建議或常見欄位
Section titled “建議或常見欄位”| 欄位 | 必要 | 說明 |
|---|---|---|
token_endpoint | REQUIRED / OPTIONAL | Token 端點(僅使用 Implicit Flow 時為 OPTIONAL) |
userinfo_endpoint | RECOMMENDED | 取得使用者資訊的端點 |
scopes_supported | RECOMMENDED | 支援的 scope 值 |
response_modes_supported | OPTIONAL | 支援的 response_mode 值 |
grant_types_supported | OPTIONAL | 支援的 grant_type 值 |
registration_endpoint | OPTIONAL | Dynamic Client Registration 的端點 |
claims_supported | RECOMMENDED | 支援的 Claims 名稱 |
實務上,RP 的套件在串接 OIDC 時,通常會自動透過 Discovery 取得這些資訊,開發者只需要提供 Issuer URL 即可。
常見的 Discovery 端點
Section titled “常見的 Discovery 端點”| Provider | Discovery URL |
|---|---|
https://accounts.google.com/.well-known/openid-configuration | |
| Microsoft | https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration |
| LINE | https://access.line.me/.well-known/openid-configuration |
與 OAuth 2.0 Authorization Server Metadata 的關係
Section titled “與 OAuth 2.0 Authorization Server Metadata 的關係”OIDC Discovery 是原始規範(2014),RFC 8414 是從它泛化而來的(2018):
| OIDC Discovery | RFC 8414 | |
|---|---|---|
| Well-known 路徑 | /.well-known/openid-configuration | /.well-known/oauth-authorization-server |
| OIDC 欄位 | 有(userinfo_endpoint、id_token_signing_alg_values_supported 等) | 無,只有通用的 OAuth 2.0 欄位 |
| 發布時間 | 2014 | 2018 |
支援 OIDC 的 OP 通常同時提供兩個端點。RFC 8414 也建議,如果 /.well-known/oauth-authorization-server 取不到,可以 fallback 到 OIDC 的 /.well-known/openid-configuration。