我想使用 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 生成的訪問令牌。我還檢查了訪問令牌的簽名也無效。此外,我改用了 ID 令牌,但仍然 401 未經授權。在 portal /AAD /App registration 中,我啟用了隱式授權流程、accessTokenAcceptedVersion: 2、在 API 權限中為我的訂閱授予管理員同意我還錯過了什么?
1 回答

飲歌長嘯
TA貢獻1951條經驗 獲得超3個贊
在您的情況下,您可以按照此使用passport.authenticate
來保護資源或 API,同時確保在使用 vue-msal 獲取令牌時使用正確的范圍。
server.get('/api/tasks', passport.authenticate('oauth-bearer', { session: false }), listTasks);
添加回答
舉報
0/150
提交
取消