gpt4 book ai didi

javascript - 如何使用 Passport-azure-ad (/w vue-msal) 保护 Web API

转载 作者:行者123 更新时间:2023-12-03 03:59:06 25 4
gpt4 key购买 nike

我想使用 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',
};
}

我提供了授权请求 header 以及 vue-msal 生成的访问 token 。
我还检查了访问 token 的签名也无效。

另外,我用ID token代替,还是401未授权。

在门户/AAD/应用程序注册中,我已启用隐式授权流程、accessTokenAcceptedVersion: 2、在 API 权限中为我的订阅授予管理员同意

我还错过了什么?

最佳答案

就您而言,您可以按照此 Use passport.authenticate to protect resources or APIs 进行操作,还要确保在使用 vue-msal 获取 token 时使用正确的范围。

server.get('/api/tasks', passport.authenticate('oauth-bearer', { session: false }), listTasks);

关于javascript - 如何使用 Passport-azure-ad (/w vue-msal) 保护 Web API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63229455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com