id_token 调用刷新令牌时格式错误

id_token is malformed when calling refresh token

作为我们 Azure API 管理设置的一部分,我们使用 oAuth 2.0 结合 Active Directory。

我们正在使用 id_token (JWT) 进行身份验证,效果很好。

我们可以通过重定向 url(Microsoft 登录)请求 id_token,此令牌可用于调用我们的 API成功(再次验证了我们的 API 政策)。

当我们要刷新令牌时出现问题。

我们遵循这个流程: https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code#refreshing-the-access-tokens

如您所见,我得到了一个 id_token 返回(因为范围 openid 已通过)但是问题也就是说,id_token 格式不正确。

而不是由 3 个部分组成,例如AAAA.BBBB.CCCC

id_token 返回,只有 2 部分(缺少签名)例如AAAA.BBBB.

用这个id_token认证时,明显失败了:(

我不确定为什么 id_token 只有两个部分,但它不是您应该发送给授权请求的访问令牌吗?也许 id_token 之前工作是因为它是由正确的授权服务器签名的,但应该一直是访问令牌?毕竟是应该刷新的访问令牌。

我假设您在最初获得有效 id_token、access_token 和 refresh_token 时将“offline_access”作为范围之一发送,否则您不应该这样做已收到 refresh_token。 https://www.rfc-editor.org/rfc/rfc6749#section-6 says that if you provide a scope on the refresh request, your access token shouldn't be limited to the scope(s) provided in the refresh request. The openid connect spec (http://openid.net/specs/openid-connect-core-1_0.html#RefreshTokenResponse) 表示刷新请求类似于令牌请求,只是它“可能不包含 id_token”。在我看来,除非它是 Azure 中特定于实现的功能,否则在刷新响应中期待 id_token 时,所有的赌注都没有了。

更新 来自 https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-code#refresh-the-access-token

"id_token--未签名的 JSON Web 令牌 (JWT)。应用程序可以 base64Url 解码此令牌的段以请求有关登录用户的信息。应用程序可以缓存值并显示它们,但它不应该依赖它们来获得任何授权或安全边界。有关 id_tokens 的更多信息,请参阅 v2.0 端点令牌参考。“

注意它是未签名的。那是你遗漏的 jwt 的第三部分。