【发布时间】:2020-07-17 18:59:19
【问题描述】:
在我的 api 验证节点应用程序中,我在 passport-azure-ad 包中使用 BearerStrategy。
在documentation中指定
用户向受保护的 web api 发送请求,该请求在授权标头或正文中包含 access_token。
如果访问令牌存储在 cookie header 而不是授权标头中,是否可以验证 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 标头中传递访问令牌 - 它未经过验证.. 我应该使用其他一些包,如 passport-cookie 吗?那么如何传递 azure 凭据以与 Azure Active Directory 集成?
【问题讨论】: