gpt4 book ai didi

azure - 如何验证 Azure Active Directory 中刷新的 id_token 的签名

转载 作者:行者123 更新时间:2023-12-03 00:03:08 25 4
gpt4 key购买 nike

我们正在使用 Azure Active Directory Oauth 代码流来对用户进行身份验证。我们使用代码获取了access_token、id_token 和refresh_token(在重定向URL 上获取)。身份验证成功后,我们使用 id_token 来授权每个请求,并且可以使用从 /discovery/v2.0/keys api 获取的公钥来验证 JWT。

现在,JWT 将在 1 小时后过期。所以我们需要刷新这个id_token。

我正在使用下面的 cURL 刷新 id_token

 curl --request POST \
--url https://login.microsoftonline.com/{tenant_id}/oauth2/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data 'client_id=client%20id&refresh_token=refesh%20token%20&grant_type=refresh_token&client_secret=client_secret&scope=openid

在这个API的响应中,我们得到了access_token、refresh_token、id_token,但是如果观察id_token,它不包含JWT签名(JWT的第三部分),没有签名我们无法验证JWT

sample response of refresh token API

我们找不到任何文档引用为什么 id_token 没有签名部分。还有其他方法刷新id_token吗?如果id_token无法刷新,有什么解决办法吗?

最佳答案

在某些情况下,可能会在没有签名的情况下返回 Id token ,特别是如果它是通过具有客户端 key 的反向 channel 获取的。您已经通过加密 channel 从权威机构获取了 token 。如果有人能够在那里注入(inject)一些东西,他们也将能够引导您的应用程序对 OpenID 元数据的请求,从而替换您的应用程序期望的签名 key 。因此签名在这里不会增加太多值(value)。

此外,您不会将 Id token 发送到任何 API,因为 Id token 不应用于授权。这就是访问 token 的用途:)

OpenID Connect 规范有这样的说法:https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation

If the ID Token is received via direct communication between the Client and the Token Endpoint (which it is in this flow), the TLS server validation MAY be used to validate the issuer in place of checking the token signature. The Client MUST validate the signature of all other ID Tokens according to JWS [JWS] using the algorithm specified in the JWT alg Header Parameter. The Client MUST use the keys provided by the Issuer.

但是,有趣的是也提到了这一点:https://openid.net/specs/openid-connect-core-1_0.html#IDToken

ID Tokens MUST be signed using JWS and optionally both signed and then encrypted using JWS and JWE respectively, thereby providing authentication, integrity, non-repudiation, and optionally, confidentiality, per Section 16.14. If the ID Token is encrypted, it MUST be signed then encrypted, with the result being a Nested JWT, as defined in [JWT]. ID Tokens MUST NOT use none as the alg value unless the Response Type used returns no ID Token from the Authorization Endpoint (such as when using the Authorization Code Flow) and the Client explicitly requested the use of none at Registration time.

那么..Azure AD 可能不符合规范?

编辑:Azure AD 的 v1 端点在这方面不符合要求。较新的 v2 端点完全符合 OpenID Connect 标准。

关于azure - 如何验证 Azure Active Directory 中刷新的 id_token 的签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61502630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com