在我的 api 验证节点应用程序中,我在passport-azure-ad包中使用BearerStrategy 。
在文档中,指定
用户向受保护的 Web api 发送请求,该请求在授权标头或正文中包含 access_token。
如果访问令牌存储在cookie 标头而不是授权标头中,是否可以验证 api?
代码如下:
const authenticationStrategy = new BearerStrategy(config.credentials, (token,
done) => {
let currentUser = null;
let userToken = authenticatedUserTokens.find((user) => {
currentUser = user;
user.sub === token.sub;
});
if (!userToken) {
authenticatedUserTokens.push(token);
}
return done(null, currentUser, token);
});
passport.use(authenticationStrategy);
server.get('/api/test', passport.authenticate('oauth-bearer', {
session: false
}), (req, res, next) => {
res.send({"message":"Success"});
return next();
});
因此,如果我在 cookie 标头中传递访问令牌 - 它未经过验证。我应该使用其他一些包,如护照 cookie 吗?那么如何通过 Azure 凭据与 Azure Active Directory 集成?