【发布时间】:2020-02-01 06:10:33
【问题描述】:
我想使用节点 js 对 Azure 活动目录中的用户进行身份验证的每个人(我真的是 azure 和活动目录中的新手),我阅读了很多文档,有两种方法可以做到这一点。 首先:我的网络请求通过微软提供给我的表单进行身份验证,然后用户登录并重定向到我的网址
第二:(这是我需要的方式)我正在使用 Oauth2,与
var BearerStrategy = require('passport-azure-ad').BearerStrategy 进行身份验证,我有我的客户 ID、tenanId、client_Secret 等。
作为第一步,我需要获得一个 Acces_token,我可以通过邮递员向该 URL 发送请求:
https://login.microsoftonline.com/My_alias_tenan/oauth2/token
我在我的身体上发送这个参数:
{grant_type: client_credentials, client_id: 1f7bbc3e-19ed-4ae5-b16d..., client_secret: 98ijhi7tuf..., resource: https://management.azure.com/, .... }
我只是关注这个博客:https://blog.jongallant.com/2017/11/azure-rest-apis-postman/
我收到了这样的令牌:
"token_type": "Bearer",
"expires_in": "3600",
"ext_expires_in": "3600",
"expires_on": "1570045543",
"not_before": "1570041643",
"resource": "https://management.azure.com/",
"access_token": "eyJ0eXAiOiJKV
我在标题中输入的下一个请求指向我的本地主机:因为在这里我可以选择发送身份验证,这是:
identityMetadata: 'https://login.microsoftonline.com/alias_tenan/v2.0/.well-known/openid-configuration',
clientID: process.env.AD_CLIENT_ID,
audience : 'https://management.azure.com/',
validateIssuer: false,
passReqToCallback: true,
isB2C: false,
allowMultiAudiencesInToken: false,
issuer:null,
loggingLevel: 'info',
loggingNoPII: false,
responseMode: query
我的代码是这样的:
return passport.authenticate('oauth-bearer', function(req, token, done) {
console.log(token)
res.status(200).json({'name': 'name'});
}
)(req, res, next)
但总是收到这条消息:
{"name":"AzureAD: Bearer Strategy","hostname":"DESKTOP-U0R9GTV","pid":1168,"level":30,"msg":"authentication failed due to: error: invalid_token","time":"2019-10-02T22:54:04.782Z","v":0}
有没有人成功做到这一点?提前致谢 我希望任何人都可以帮助我。
【问题讨论】:
标签: node.js authentication oauth-2.0 azure-active-directory bearer-token