【问题标题】:tokenReceivedCallback is not called when using MSAL AngularJS with Azure B2C将 MSAL AngularJS 与 Azure B2C 结合使用时,不会调用 tokenReceivedCallback
【发布时间】:2019-07-04 01:49:49
【问题描述】:

在做

msalService.loginPopup();

然后:

$rootScope.$on("msal:loginSuccess", function () {
    console.log("loginSuccess");

    var token = msalService.userInfo.idToken;
});

我可以看到userInfo.isAuthenticated 为真,并且存在一个 id 令牌。

但是,tokenReceivedCallback 永远不会被调用。

msalProvider.init({
    clientID: "Client ID here",
    authority: "https://login.microsoftonline.com/tfp/myb2caad.onmicrosoft.com/B2C_1_SignUpSignIn",
    validateAuthority: false,
    //consentScopes: ["https://myb2caad.onmicrosoft.com/test/user_impersonation"],
    tokenReceivedCallback: function (errorDesc, token, error, tokenType) {
        debugger;
        if (token) {
            console.log('Token type: ' + tokenType + ' Token: ' + token)
        }
        else {
            console.log(errorDesc + error)
        }
    }
},
    $httpProvider // Optionally, pass http provider to inject request interceptor to attach tokens
);

您能发现问题或给出一些提示吗?

【问题讨论】:

  • 嗨@Leniel。 tokenReceivedCallback 只能通过重定向而不是提示来调用登录。

标签: angularjs azure-ad-b2c bearer-token msal msal.js


【解决方案1】:

原来问题与hashPrefix 有关。应用程序搞砸了。

我必须这样做:

app.config(['$locationProvider', function($locationProvider) {
    $locationProvider.html5Mode(false).hashPrefix('');
}]);

hashPrefix 干扰了回调。

这里提到了:https://www.npmjs.com/package/@azure/msal-angularjs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-15
    • 2020-07-14
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    相关资源
    最近更新 更多