繁体   English   中英

使用node.js检索来自azure ad b2c登录的声明

[英]retrieve claims coming from azure ad b2c login using node.js

我正在使用Azure AD B2C执行身份验证。 成功登录后,我在浏览器中看到如下内容:

本地主机:3000 /#id_token = eyJ0elll ...

我想知道如何在我的Nodejs后端中检索该令牌

听起来您好像遵循了教程Azure Active Directory B2C: Web sign-in with OpenID Connect进行Azure Active Directory B2C: Web sign-in with OpenID Connect以发送URL的身份验证请求,例如https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/oauth2/v2.0/authorize?.....并获得30x localhost:3000/#id_token=eyJ0elll...&code=AwABAAAA...&state=arb....响应,以重定向到浏览器中的localhost:3000/#id_token=eyJ0elll...&code=AwABAAAA...&state=arb.... 现在,您想在没有浏览器的NodeJS中实现它。

这是我使用request/request简单代码。

const request = require('request');
var url = require("url");
var querystring = require("querystring");
var authorize_uri = 'https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/oauth2/v2.0/authorize?.....';
request(authorize_uri, function (error, response, body) {
    var href = response.request.href; // get localhost:3000/#id_token=eyJ0elll...&code=AwABAAAA...&state=arb....
    var hash = url.parse(href).hash; // get #id_token=eyJ0elll...&code=AwABAAAA...&state=arb....
    //var hash = response.request.uri.hash; // or directly get #id_token=eyJ0elll...&code=AwABAAAA...&state=arb....
    var id_token = querystring.parse(hash)['#id_token'];
    console.log(id_token);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM