我需要从 Azure Active Directory 获取 OAuth2 访问 token 。为此,我使用基于证书的方法。我已将 .crt 文件上传到 Azure AD 并从 Azure AD UI 获取了证书指纹。
现在我正在从 JWT.io 生成 JWT token 并使用 postman 进行尝试。但我总是收到以下错误: “AADSTS700027:客户端断言包含无效签名。[原因 - 未找到 key 。客户端使用的 key 指纹”
我不确定是什么原因造成的。在 JWT.io 中,我输入公共(public)证书(我在 Azure AD 上上传)的 Base64 编码指纹作为 x5t 参数。如上所述,我从 Azure 门户 UI 获得了这个指纹。
在 JWT.io 中,我在“验证签名”下输入公共(public)(crt)和私有(private)( key )证书,可以看到签名已匹配。
如果有人对此有任何想法,请告诉我。
最佳答案
据我所知,这个错误通常是由于您没有正确编码指纹造成的。获取指纹后,请检查您的代码以确保它已正确进行 Base64 编码。
在 https://jwt.io/ 检查您的 JWT token 的格式,可以引用this和 certificate credentials :
标题
{
"alg": "RS256",
"typ": "JWT",
"x5t": "<Base64 Thumbprint>"
}
有效负载
{
"iss": "<clientid>",
"sub": "<clientid>",
"exp": 1570838377 (expiration time),
"jti": "<random unique identifier>",
"aud": "https://<token-endpoint>"
}
将您的私钥放入底部验证器,它将在“已编码”窗口中为您的 JWT 签名。
我找了一些案例供大家引用,希望对大家有所帮助: https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/320069/authentication-to-dynamics-365-using-azure-apps 和 https://github.com/AzureAD/passport-azure-ad/issues/453
关于oauth-2.0 - 智威汤逊 token 。错误 "AADSTS700027: Client assertion contains an invalid signature",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62716173/