я пытаюсь реализовать Msal для B2 c вход в систему Angular 8, после входа я сохраняю токен в локальном хранилище, я сделал это с loginPopup, и он работал хорошо:
//msal.service.ts
signIn() {
this.myMSALObj.loginPopup(this.loginRequest).then(function (idToken: any) {
this.myMSALObj.acquireTokenSilent(this.tokenRequest).then(
function (accessToken: any) {
this.saveAccessTokenToCache(accessToken);
}, function (error: any) {
this.myMSALObj.acquireTokenPopup(this.tokenRequest).then(
function (accessToken: any) {
this.saveAccessTokenToCache(accessToken);
}, function (error: any) {
console.log("error: ", error);
});
})
}, function (error: any) {
console.log("error: ", error);
});
}
Теперь я пытаюсь реализовать логин с помощью loginRedirect (), я использовал handleRedirectCallback для сохранения токена, но он не вызывался:
//msal.service.ts
constructor(private router: Router, private shareService: ShareService){
this.myMSALObj.handleRedirectCallback((error, response) => {
if(response){
this.myMSALObj.acquireTokenSilent(this.tokenRequest).then(function(accessTokenResponse) {
// Acquire token silent success
// call API with token
let accessToken = accessTokenResponse.accessToken;
this.saveAccessTokenToCache(accessToken);
}).catch(function (error) {
//Acquire token silent failure, send an interactive request.
console.log(error);
if (error.errorMessage.indexOf("interaction_required") !== -1) {
this.myMSALObj.acquireTokenRedirect(this.tokenRequest);
}
});}
});
}
signIn(){
this.myMSALObj.loginRedirect(this.loginRequest);
}
что мне делать? спасибо