![](/img/trans.png)
[英]using passport-azure-ad configuration to secure a web app and web server via OIDCStrategy and BearerStrategy
[英]How to secure Web API with passport-azure-ad (/w vue-msal)
我想用 passport-azure-ad 保护 Web API 并使用 bearerStrategy。 我遵循模块提供的示例并传递元数据和clientId,我总是得到401未经授权。
这是我的 passport-azure-ad 配置
{
identityMetadata: 'https://login.microsoftonline.com/<your_tenant_guid>/v2.0/.well-known/openid-configuration'
// Required
clientID: '<client ID>',
// Required.
// If you are using the common endpoint, you should either set `validateIssuer` to false, or provide a value for `issuer`.
validateIssuer: false,
// Required.
// Set to true if you use `function(req, token, done)` as the verify callback.
// Set to false if you use `function(req, token)` as the verify callback.
passReqToCallback: false,
// Optional. Default value is false.
// Set to true if you accept access_token whose `aud` claim contains multiple values.
allowMultiAudiencesInToken: false,
loggingLevel:'error',
};
}
我使用 vue-msal 生成的访问令牌提供了授权请求 header。
我还检查了访问令牌的签名也无效。
此外,我使用了 ID 令牌,但仍然 401 未经授权。
在门户 /AAD /App 注册中,我在 API 权限中启用了隐式授权流、 accessTokenAcceptedVersion: 2
、为我的订阅授予管理员同意
我还错过了什么?
在您的情况下,您可以按照此Use passport.authenticate
to protect resources or APIs ,并确保在使用 vue-msal 获取令牌时使用正确的 scope 。
server.get('/api/tasks', passport.authenticate('oauth-bearer', { session: false }), listTasks);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.