【问题标题】:acquireTokenSilent with angular and microsoft msal fails with AADB2C90077 / AADB2C90205带有角度和微软 msal 的 acquireTokenSilent 因 AADB2C90077 / AADB2C90205 而失败
【发布时间】:2020-04-10 21:10:11
【问题描述】:

我正在尝试使用 angular9 和 microsoft/msal 从 AAD B2C 配置中获取令牌

我的模块配置是这样的;

MsalModule.forRoot(
            {
                auth: {
                    clientId: "xxxxxxxxxxxxxxxxx",
                    authority:
                        "https://login.microsoftonline.com/tfp/isthereanynewscodeblast.onmicrosoft.com/B2C_1_itansignup",
                    validateAuthority: false,
                },
                cache:{
                    cacheLocation:"localStorage",
                    storeAuthStateInCookie:true
                }
            }
        ),

这用于登录并且有效。我能够获得这样的基本信息:

下一次登录后,我会尝试为图形数据或我的自定义范围获取更多数据,如下所示:

getToken() {
        const accessTokenRequest = {
             scopes: [
                 "https://graph.microsoft.com/User.Read",
            //     // "https://isthereanynewscodeblast.onmicrosoft.com/05cd7635-e6f4-47c9-a5ce-8ec04368b297/application_reader",
            //     // "https://isthereanynewscodeblast.onmicrosoft.com/05cd7635-e6f4-47c9-a5ce-8ec04368b297/application_writer",
             ],
            clientId: "xxxxxxxxxxxxxxxx",
            authority: "https://login.microsoftonline.com/tfp/isthereanynewscodeblast.onmicrosoft.com/B2C_1_itansignup",
            redirectUri: "http://localhost:4200",
            // postLogoutRedirectUri: 'http://localhost:4200/',
        };
        this.authService
            .acquireTokenSilent(accessTokenRequest)
            .then((res) => {
                console.log("acquireTokenPopup");
                this.token = res.accessToken;
                this.getUser();
            })
            .catch((e) => {
                console.log("acquireTokenPopup catch");
                console.log(e);
            });
    }

获取令牌失败并出现以下错误:

InteractionRequiredAuthError: AADB2C90077: User does not have an existing session and request prompt parameter has a value of 'None'.

我不知道我做错了什么或在哪里寻找答案:

  • 我的示波器看起来不错(^C^V - 名称和链接)

  • 我尝试将用户流会话行为更改为禁用

  • 更改acquireTokenPopup 返回此错误:

    ServerError: AADB2C90205: This application does not have sufficient permissions against this web resource to perform the operation.

【问题讨论】:

    标签: angular azure azure-ad-b2c msal


    【解决方案1】:

    首先,不推荐使用 B2C 中的 microsoftonline.com URL (link)。 你应该使用这样的东西作为你的权威:

    `https://${tenant}.b2clogin.com/${tenant}.onmicrosoft.com/${policyId}`
    

    此外,目前无法代表 B2C 用户访问 MS Graph API。 因此,您不应指定 MS Graph API 范围。 您应该能够为已注册为 B2C 应用的 API 指定范围:

    app.acquireTokenSilent({ scopes: ['api-client-id/ScopeName'] });
    

    或者如果你想要一个 id 令牌,你可以指定客户端 id:

    app.acquireTokenSilent({ scopes: [clientId] });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 2021-12-13
      • 2016-04-29
      • 1970-01-01
      • 1970-01-01
      • 2020-08-19
      • 2017-08-31
      相关资源
      最近更新 更多