为啥jwt.io不能解码google JWT token

Posted

技术标签:

【中文标题】为啥jwt.io不能解码google JWT token【英文标题】:Why can't the google JWT token be decoded by jwt.io为什么jwt.io不能解码google JWT token 【发布时间】:2018-07-15 08:57:33 【问题描述】:

我在 Azure App Service .NET Core 应用程序中启用了 Google 身份验证,我正在尝试使用 Postman 生成访问令牌:

一个access token 和一个id_token 成功生成,但是当我将access token 输入jwt.io 时,我看到了乱码:

我是 google auth 和 JWT 的新手,所以我的期望可能完全无效,但我不应该能够解码 jwt.io 上的令牌吗?

【问题讨论】:

RFC6749 section 1.4: An access token is a string representing an authorization issued to the client. **The string is usually opaque to the client** 【参考方案1】:

在我看来,您在编码区域中只粘贴了标记的两部分,我在字符串中只看到了 1 个点。在 jwt.io 给出的示例中,其中有 2 个点将其分为 3 个部分。

【讨论】:

再挖了一些之后,似乎我粘贴了错误的部分。正如我所提到的,我收到了access tokenid token。我粘贴了access token,但似乎只有id token 是JWT 组件。但我很困惑有什么区别。 我不熟悉 Postman,但 JWT 总是包含三个部分,用点分隔。第一个是标头,第二个是有效载荷数据。第三个是通常加密的签名。【参考方案2】:

访问令牌不是 JWT。 id_token 是一个 JWT,您应该能够使用 jwt.io 对其进行解码。

区别在于 OAuth 2.0 和 OpenID Connect 之间的区别。

访问令牌用于向 Google API 发出额外请求: https://developers.google.com/identity/protocols/OAuth2WebServer#callinganapi

id_token 已经保存了验证用户的信息: https://developers.google.com/identity/protocols/OpenIDConnect#obtainuserinfo

【讨论】:

以上是关于为啥jwt.io不能解码google JWT token的主要内容,如果未能解决你的问题,请参考以下文章

JWT在jwt.io上解码,但在应用程序中没有

使用 RS256 生成的 JWT 可以被 jwt.io 网站解码吗?

为啥我的来自 Amazon Cognito 的 JWT 令牌具有无效签名?

为啥即使我没有在 Jwt.io 中提供秘密(签名),jwt 令牌也会显示有效负载?

使用 google auth 库验证 JWT

JWT 解码返回 null