我使用Azure AD B2C Portal生成令牌。当我使用loginPopup方法时,我可以成功生成令牌但在使用loginRedirect时获得undefined
。
这是代码:
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 :(得分:0)
我找到了reference。通过这个我能够实现访问令牌。你会在sessionStorage.getItem('msal.idtoken')
中得到它。
答案 1 :(得分:-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);
}