JWT 令牌。错误“AADSTS700027:客户端断言包含无效签名”

use*_*866 5 oauth-2.0 jwt azure-active-directory postman

我需要从 Azure Active Directory 获取 OAuth2 访问令牌。为此,我使用基于证书的方法。我已将 .crt 文件上传到 Azure AD 并从 Azure AD UI 获取了证书指纹。

现在我正在从 JWT.io 生成 JWT 令牌并使用邮递员尝试它。但我总是收到以下错误:“AADSTS700027:客户端断言包含无效签名。[原因 - 找不到密钥。客户端使用的密钥的指纹”

我不确定是什么原因造成的。在 JWT.io 中,我输入公共证书的 Base64 编码指纹(我在 Azure AD 上上传)作为 x5t 参数。如上所述,我从 Azure 门户 UI 获得了该指纹。

在 JWT.io 中,我在“验证签名”下输入公共(crt)和私有(密钥)证书,并且可以看到签名已匹配。

如果有人对此有任何想法,请告诉我。

Car*_*hao 1

据我所知,此错误通常是由于您没有正确编码指纹而引起的。获取指纹后,请检查您的代码以确保它已正确进行 Base64 编码。

在https://jwt.io/检查您的 JWT 令牌的格式,您可以参考证书凭据

标头

{
  "alg": "RS256",
  "typ": "JWT",
  "x5t": "<Base64 Thumbprint>"
}
Run Code Online (Sandbox Code Playgroud)

有效载荷

{
  "iss": "<clientid>",
  "sub": "<clientid>",
  "exp": 1570838377 (expiration time),
  "jti": "<random unique identifier>",
  "aud": "https://<token-endpoint>"
}
Run Code Online (Sandbox Code Playgroud)

将您的私钥放入底部验证器,该验证器将在“编码”窗口中签署您的 JWT。

我找到了一些案例供您参考,希望对您有所帮助: https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/320069/authentication-to-dynamics-365-using-azure -appshttps://github.com/AzureAD/passport-azure-ad/issues/453