0

我使用Azure AD B2C门户生成令牌。当我使用loginPopup方法时,我可以成功生成Token,但在使用loginRedirect时获得undefined在Azure AD中使用loginRedirect生成访问令牌B2C门户

下面的代码:

clientApplication = new Msal.UserAgentApplication(
     this.tenantConfig.clientID, this.authority, 
     function (errorDesc: any, token: any, error: any, tokenType: any) { 
      // Called after loginRedirect or acquireTokenPopup 
     } 
); 

public login(): void { 
     var _this = this; 
     // loginRedirect loginPopup 
     this.clientApplication.loginPopup(this.tenantConfig.b2cScopes).then(function (idToken: any) { 
      _this.clientApplication.acquireTokenSilent(_this.tenantConfig.b2cScopes).then(
       function (accessToken: any) { 
        _this.access_token = accessToken; 
       }, function (error: any) { 
        _this.clientApplication.acquireTokenPopup(_this.tenantConfig.b2cScopes).then(
         function (accessToken: any) { 
          _this.access_token = accessToken; 
         }, function (error: any) { 
          bootbox.alert("Error acquiring the popup:\n" + error); 
         }); 
       }) 
     }, function (error: any) { 
      bootbox.alert("Error during login:\n" + error); 
     }); 
     console.log(`access token service file ${_this.access_token}`); 
    } 

请让我知道我在做什么错误?是范围问题还是回调方法问题?

回答

0

我找到了reference。由此我能够实现访问令牌。你会得到它在sessionStorage.getItem('msal.idtoken')

+0

我在msal.nonce.idtoken中找到了此内容 –

-1

对于loginRedirect,您在// Called after loginRedirect or acquireTokenPopup区块中添加您的处理程序代码。

clientApplication = new Msal.UserAgentApplication(
     this.tenantConfig.clientID, this.authority, 
     function (errorDesc: any, token: any, error: any, tokenType: any) { 
      // Called after loginRedirect or acquireTokenPopup 
      // perform your logic HERE! :) 
     } 
); 

public login(){ 
    this.clientApplication.loginRedirect(this.tenantConfig.b2cScopes); 
} 
+0

以上不会在Angular 4应用程序中的loginredirect后调用。 –

+0

@ShailenSukul它为我做!请参阅此示例应用程序[NetCoreAngularAzureB2CMsal](https://github.com/spottedmahn/NetCoreAngularAzureB2CMsal/blob/master/ClientApp/app/services/authentication.service.ts) – spottedmahn