【发布时间】:2019-08-23 15:51:54
【问题描述】:
我在使用 passport-azure-ad 库时遇到问题,该库在尝试验证 id_token 时抛出错误。具体报错信息为"authentication failed due to: In _validateResponse: failed to generate PEM key due to: a key with kid %s cannot be found"
我可以看到id_token 标头中的kid 是一个未出现在密钥发现端点(格式为https://login.microsoftonline.com/{tenantId}/discovery/v2.0/keys)中的值。
有什么理由会发生这种情况吗?我想不通。
我的代码如下:
passport.use(
new OIDCStrategy({
clientID: CLIENT_ID,
clientSecret: CLIENT_SECRET,
identityMetadata: IDENTITY_METADATA_URL,
redirectUrl: SUCCESS_REDIRECT_URI,
responseMode: 'form_post',
responseType: 'code',
scope: 'email profile',
loggingLevel: 'info',
loggingNoPII: false
})
)
app.get(
'/oauthv2/login',
passport.authenticate(
'azuread-openidconnect',
{ failureRedirect: '/fail' },
(req, res) => {
// ...
}
)
)
app.post(
'/oauthv2/success',
passport.authenticate(
'azuread-openidconnect',
{ failureRedirect: '/' },
(req, res) => {
// ...
}
)
)
从pazzport-azure-ad日志中我可以看到在错误发生之前执行了以下步骤:
- 收到 id_token
- 收到 access_token
- 收到 refresh_token
- 令牌解码
- 处理密钥
- 处理密钥
- 处理密钥
- 身份验证失败,原因是:在 _validateResponse 中:无法生成 PEM 密钥,原因是:找不到孩子 %s 的密钥
【问题讨论】:
标签: javascript node.js openid-connect passport-azure-ad