[英]Azure AD B2C signUp
我已經在 Azure 門戶中配置了一個應用程序並設置了必要的用戶策略:簽名和注冊、密碼重置。 我選擇了一起登錄和注冊的用戶策略。 我已經創建了一個示例 Nodejs 應用程序,參考了 azure b2c 的 Microsoft 文檔,如下所示,
const express = require("express");
const msal = require('@azure/msal-node');
const SERVER_PORT = process.env.PORT || 3000;
// Create Express App and Routes
const app = express();
const config = {
auth: {
clientId: "******",
authority: "https://login.microsoftonline.com/<tenantid>",
clientSecret: "*****"
},
system: {
loggerOptions: {
loggerCallback(loglevel, message, containsPii) {
console.log(message);
},
piiLoggingEnabled: false,
logLevel: msal.LogLevel.Verbose,
}
}
};
// Create msal application object
const cca = new msal.ConfidentialClientApplication(config);
app.get('/', (req, res) => {
const authCodeUrlParameters = {
scopes: ["user.read"],
redirectUri: "http://localhost:3000/auth/openid/return",
};
// get url to sign user in and consent to scopes needed for application
cca.getAuthCodeUrl(authCodeUrlParameters).then((response) => {
res.redirect(response);
}).catch((error) => console.log(JSON.stringify(error)));
});
app.get('/auth/openid/return', (req, res) => {
const tokenRequest = {
code: req.query.code,
scopes: ["user.read"],
redirectUri: "http://localhost:3000/auth/openid/return",
};
cca.acquireTokenByCode(tokenRequest).then((response) => {
console.log("\nResponse: \n:", response);
res.sendStatus(200);
}).catch((error) => {
console.log(error);
res.status(500).send(error);
});
});
app.listen(SERVER_PORT, () => console.log(`Msal Node Auth Code Sample app listening on port ${SERVER_PORT}!`))
使用此代碼,我可以查看登錄/登錄頁面,但我不確定如何在此處添加注冊選項,以便我可以使用身份提供者向租戶注冊用戶。 如何在此處獲得注冊頁面/選項? 有人可以幫我解決這個問題嗎?
• 您可以在azure AD B2C 中的node js 應用程序中添加注冊頁面信息,如下所示,使用代碼中使用的變量: -
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var session = require('express-session');
var okta = require("@okta/okta-sdk-nodejs");
var ExpressOIDC = require("@okta/oidc-middleware").ExpressOIDC;
var oktaClient = new okta.Client({
orgUrl: '{yourOktaOrgUrl}',
token: '{yourOktaToken}'
});
const oidc = new ExpressOIDC({
issuer: "{yourOktaOrgUrl}/oauth2/default",
client_id: {yourClientId},
client_secret: {yourClientSecret},
redirect_uri: 'http://localhost:3000/users/callback',
scope: "openid profile",
routes: {
login: {
path: "/users/login"
},
callback: {
path: "/users/callback",
defaultRedirect: "/dashboard"
}
}
});
通過這種方式,您可以在 node js web 應用程序代碼中添加插入用戶注冊選項的選項。
請找到以下鏈接以獲取更多信息:-
https://github.com/instafluff/NodeJS-on-Azure-Cloud-Native-Authentication
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.