OIDC 发现端点
学习 OIDC 发现端点如何让客户端以编程方式获取所有必要的 OIDC 配置信息。
OIDC 发现端点 是 CoddyKit 上的免费 OAuth2 & OpenID Connect Deep Dive 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 OAuth2 & OpenID Connect Deep Dive 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 OAuth2 & OpenID Connect Deep Dive 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
What is OIDC Discovery?
Imagine you're building an application that needs to connect to an OpenID Provider (IdP) like Google or Auth0. How do you know its authorization URL, token URL, or how to get its public keys?
Manually configuring these details for every IdP is tedious and error-prone. This is where OIDC Discovery comes in!
The Discovery Endpoint
OIDC Discovery provides a standardized way for clients to find all the necessary configuration information of an OpenID Provider.
Instead of hardcoding URLs, your client application can fetch a single JSON document from a well-known URL. This document contains all the endpoints and capabilities of the IdP.
Finding the Discovery Document
Clients typically access the OIDC Discovery document at a specific, standardized URL:
- Base URL of the OpenID Provider
- Followed by
/.well-known/openid-configuration
For example, if your IdP's base URL is https://accounts.example.com, the discovery endpoint would be https://accounts.example.com/.well-known/openid-configuration.
Key Fields: Issuer & JWKS URI
The discovery document is a JSON object with many fields. Two crucial ones are:
issuer: A URL that uniquely identifies the OpenID Provider. It must match theissclaim in ID Tokens.jwks_uri: The URL of the JSON Web Key Set (JWKS) document. This document contains the public keys used by the IdP to sign ID Tokens, allowing your client to verify their authenticity.
Key Fields: Endpoints
The discovery document lists the various endpoints your client will interact with:
authorization_endpoint: Where the user is redirected to grant consent.token_endpoint: Where the client exchanges the authorization code for access and ID tokens.userinfo_endpoint: Where the client can request user profile information after obtaining an access token.end_session_endpoint: (Optional) Where the client can redirect the user to log out from the IdP.
Key Fields: Capabilities
The document also declares the IdP's capabilities:
scopes_supported: A list of the OAuth 2.0scopevalues that this IdP supports.response_types_supported: A list of the OAuth 2.0response_typevalues that this IdP supports.grant_types_supported: (Optional) A list of the OAuth 2.0grant_typevalues that this IdP supports.
These help your client understand what features are available.
Example Discovery Document
Here's a simplified example of what an OIDC Discovery document might look like:
{
"issuer": "https://example.com/openid",
"authorization_endpoint": "https://example.com/openid/auth",
"token_endpoint": "https://example.com/openid/token",
"userinfo_endpoint": "https://example.com/openid/userinfo",
"jwks_uri": "https://example.com/openid/jwks",
"scopes_supported": [
"openid",
"profile",
"email"
],
"response_types_supported": [
"code",
"id_token",
"token id_token"
],
"grant_types_supported": [
"authorization_code",
"implicit",
"refresh_token"
],
"id_token_signing_alg_values_supported": [
"RS256"
]
}How Clients Use Discovery
A client application can perform OIDC Discovery by:
- Fetching the JSON document from the
/.well-known/openid-configurationendpoint. - Parsing the JSON to extract the necessary URLs and capabilities.
- Using these dynamically discovered values to construct authorization requests, exchange tokens, and validate ID Tokens.
This makes client integration much more robust and future-proof.
Benefits of Discovery
Using OIDC Discovery offers several advantages:
- Reduced Configuration: Clients don't need to hardcode IdP endpoints.
- Increased Flexibility: IdPs can change endpoint URLs without breaking clients.
- Enhanced Security: Clients can easily find the
jwks_urito verify ID Token signatures. - Interoperability: Promotes a standardized way for clients to interact with any OIDC-compliant IdP.
Test Your Knowledge
Which of the following fields in the OIDC Discovery document is used by a client to verify the signature of an ID Token?
Recap: OIDC Discovery
We've learned that OIDC Discovery provides a standardized way for clients to find an OpenID Provider's configuration.
- Clients access a well-known
/.well-known/openid-configurationendpoint. - The returned JSON document contains essential URLs (authorization, token, userinfo, jwks) and capabilities (scopes, response types).
- This automation simplifies client setup, improves flexibility, and enhances security by providing necessary public keys for token validation.
常见问题解答
「OIDC 发现端点」课时是免费的吗?
是的 — 「OIDC 发现端点」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 OAuth2 & OpenID Connect Deep Dive 课程的其余内容,请升级到 CoddyKit PRO。 OAuth2 & OpenID Connect Deep Dive 课程共包含 4 节课。
「OIDC 发现端点」这节课中我会学到什么?
学习 OIDC 发现端点如何让客户端以编程方式获取所有必要的 OIDC 配置信息。 你通过在浏览器中直接运行的动手代码来练习 OAuth2 & OpenID Connect Deep Dive,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 OAuth2 & OpenID Connect Deep Dive 需要有经验吗?
无需任何先前经验。CoddyKit 上的 OAuth2 & OpenID Connect Deep Dive 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「OIDC 发现端点」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 OAuth2 & OpenID Connect Deep Dive 课中编写并运行代码吗?
能。每节 OAuth2 & OpenID Connect Deep Dive 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。