我一直在尝试使用 React JS 在前端集成我的 Azure AD B2C 身份验证服务。我面临的问题是我无法在请求 URL 中传递查询参数,这就是为什么将 signInPolicy (p) 作为 null 传递。我不知道我做错了什么。还尝试了来自互联网的不同解决方案。目前,我一直在使用 @azure/msal-react npm 包。列出了我的配置代码和我面临的问题:
// inside Config.js
export const msalConfig = {
auth: {
authority:
`https://{TENANT_SUB_DOMAIN}.b2clogin.com/{TENANT_OR_DOMAIN_NAME}/B2C_1_signupsignin`,
clientId: "MY_CLIENT_ID",
signInPolicy: "B2C_1_signupsignin",
prompt: "login",
knownAuthorities: ["checkappb2c.b2clogin.com"],
redirectUri: 'https%3A%2F%2Fa{MY_APP_NAME}-alpha.azurewebsites.net',
validateAuthority: false,
postLogoutRedirectUri: 'http://localhost:3000'
},
cache: {
cacheLocation: "sessionStorage", // This configures where your cache will be stored
storeAuthStateInCookie: false, // Set this to "true" if you are having issues on IE11 or Edge
},
}
export const loginRequest = {
scopes: ["User.Read"],
extraQueryParameters: {signInPolicy: 'B2C_1_signupsignin', p : 'B2C_1_signupsignin'}
};
// inside App.js
const { instance, accounts } = useMsal();
const [graphData, setGraphData] = useState(null);
function RequestProfileData() {
// Silently acquires an access token which is then attached to a request for MS Graph data
instance.acquireTokenSilent({
...loginRequest,
account: accounts[0]
}).then((response) => {
callMsGraph(response.accessToken).then(response => setGraphData(response));
});
}