0

我一直在尝试使用 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));
    });
}

// 我面临的问题:在此处输入图像描述

4

1 回答 1

0

您不需要 p 参数,您可以在路径或 p 参数中有策略。你的在路上。

https://docs.microsoft.com/en-us/azure/active-directory-b2c/openid-connect#send-authentication-requests

User.read 是无效范围。创建您自己的范围并将其传入。

https://docs.microsoft.com/en-us/azure/active-directory-b2c/configure-authentication-sample-spa-app#step-2-register-your-spa-and-api

您不能使用 B2C 令牌调用 Graph API,因此您的获取配置文件代码将不起作用。

于 2021-11-16T09:22:50.007 回答