使用 response_type=code
对支持 OpenID 的 OAuth2 授权服务器进行身份验证后与 scope=openid email
,调用 token 端点应返回 id_token
.
我缺少的是这是否id_token
应该包含 email
与否 - 在这种情况下,客户应调用 userInfo
端点。
规范说:
http://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims
The Claims requested by the profile, email, address, and phone scope values are returned from the UserInfo Endpoint, as described in Section 5.3.2, when a response_type value is used that results in an Access Token being issued. However, when no Access Token is issued (which is the case for the response_type value id_token), the resulting Claims are returned in the ID Token.
据我了解,这意味着
id_token
不需要包含email
如果 access_token
可用作 userInfo
应该被调用来获取它。然而,在 https://github.com/bitly/oauth2_proxy 中查看 oidc 客户端的实现看来他们确实需要 email
声称在内部可用 id_token
无需调用 userInfo
端点。OpenID 兼容授权服务器中的正确行为是什么?
最佳答案
openid 规范比 Google 或 Microsoft 正在做的更严格(可能其他提供商也是如此,但我没有检查)。
我猜 oauth2_proxy 保留了提供者的行为。
例如谷歌,返回 id_token
交换时您要求的范围内的所有权利要求code
为 access_token
.但是如果你阅读他们的文档,他们会指定 userInfo
端点:
https://developers.google.com/identity/protocols/OpenIDConnect
我想只要你支持所有的端点,目标是否返回id_token
连同所有权利要求以及 access_token
你决定。它删除了对 userInfo
的一个额外调用。在大多数情况下,它不会暴露任何漏洞。
关于email - 在授权代码流程中使用时,id_token 是否应包含声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50740532/