openid-connect
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpenID Connect (OIDC)
OpenID Connect (OIDC)
OIDC extends OAuth 2.0 to provide Identity. While OAuth handles "Access" (Authorization), OIDC handles "Who are you?" (Authentication).
OIDC 扩展了 OAuth 2.0 以提供身份认证能力。OAuth 负责处理“访问权限”(授权),而 OIDC 负责处理“你是谁?”(身份验证)。
When to Use
使用场景
- Single Sign-On (SSO): One login for multiple apps.
- User Profile: Getting ,
name,emailfrom a provider.picture - Enterprise Identity: Connecting to Active Directory via OIDC.
- 单点登录(SSO):一次登录即可访问多个应用。
- 用户信息获取:从身份提供商处获取、
name、email等信息。picture - 企业身份集成:通过 OIDC 连接到 Active Directory。
Quick Start
快速开始
http
// Request
GET /authorize?
response_type=code&
scope=openid profile email& <-- 'openid' scope triggers OIDC
client_id=...&
redirect_uri=...
// Token Response
{
"access_token": "SlAV32hkKG...", // For API access
"id_token": "eyJ0eXKiOiJK...", // JWT containing User Profile
"expires_in": 3600
}http
// 请求
GET /authorize?
response_type=code&
scope=openid profile email& <-- 'openid' 作用域会触发 OIDC 流程
client_id=...&
redirect_uri=...
// 令牌响应
{
"access_token": "SlAV32hkKG...", // 用于 API 访问
"id_token": "eyJ0eXKiOiJK...", // 包含用户信息的 JWT
"expires_in": 3600
}Core Concepts
核心概念
ID Token
ID Token
A JSON Web Token (JWT) that contains claims (assertions) about the authentication event and the user.
一种 JSON Web Token (JWT),包含关于身份验证事件和用户的声明(断言)。
UserInfo Endpoint
UserInfo 端点
A standard OAuth protected endpoint () where you can send the Access Token to get more user details.
/userinfo一个标准的 OAuth 受保护端点 (),你可以在此发送 Access Token 以获取更多用户详细信息。
/userinfoScopes
作用域(Scopes)
- : Required to use OIDC.
openid - : Request access to name, picture, etc.
profile - : Request access to email.
email
- :使用 OIDC 必须包含的作用域。
openid - :请求访问用户姓名、头像等信息。
profile - :请求访问用户邮箱。
email
Common Patterns
常见模式
Discovery Endpoint
发现端点
/.well-known/openid-configuration/.well-known/openid-configurationBest Practices
最佳实践
Do:
- Validate the ID Token Signature (using JWKS).
- Check the Audience () claim matches your Client ID.
aud - Check the Issuer () claim matches the provider.
iss - Use Nonce to prevent replay attacks.
Don't:
- Don't treat the Access Token as an ID Token (Access Tokens are opaque strings in standard OAuth, though often JWTs in practice).
- Don't accept unsigned ID tokens (algorithm ).
none
建议:
- 验证ID Token 签名(使用 JWKS)。
- 检查受众 () 声明是否与你的客户端 ID 匹配。
aud - 检查颁发者 () 声明是否与身份提供商一致。
iss - 使用Nonce防止重放攻击。
不建议:
- 不要将 Access Token 当作 ID Token 使用(标准 OAuth 中 Access Token 是不透明字符串,尽管实际中常为 JWT)。
- 不要接受未签名的 ID Token(算法 )。
none
Troubleshooting
故障排查
| Error | Cause | Solution |
|---|---|---|
| Scope | Add |
| Wrong Public Key. | Refresh JWKS from the discovery endpoint. |
| 错误信息 | 原因 | 解决方案 |
|---|---|---|
| 未请求 | 在作用域中添加 |
| 公钥错误 | 从发现端点刷新 JWKS。 |