[英]Error in Logout through MSAL.JS in Javascript / Angular 6 SPA application using B2C
我有一個使用MSAL.JS針對Azure AD B2C進行身份驗證的Javascript SPA應用程序,還有一個使用MSAL針對Azure AD B2C用於Angular身份驗證的Angular 6 SPA應用程序。
在這兩個應用程序中,注銷均拋出錯誤。
相關ID:6de6e068-7b07-4d24-bac4-c1af3131815b時間戳記:2018-09-25 16:16:20Z AADB2C90272:在請求中未指定id_token_hint參數。 請提供令牌,然后重試。
對於注銷,MSAL具有非常簡單的注銷api,它不帶任何參數,因此如何提供id_token_hint? 我想念什么嗎? 在Angular Application中注入MsalModule時是否需要提供任何配置參數。 或Msal.UserAgentApplication的Javascript應用中類似的內容。
我基本上使用的是當前最新的“ msal”:“ ^ 0.2.3”,這是我的身份驗證服務,在app.module中不需要配置,並且注銷可以正常工作:
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import * as Msal from 'msal';
import { User } from "msal/lib-commonjs/User";
import { ApiService } from './api.service';
import { BackendRoutes } from './backend.routes';
@Injectable()
export class AuthenticationService {
private _clientApplication: Msal.UserAgentApplication;
private _authority: string;
constructor(private apiService: ApiService, private backendRoutes: BackendRoutes) {
this._authority = `https://login.microsoftonline.com/tfp/${environment.tenant}/${environment.signUpSignInPolicy}`;
this._clientApplication =
new Msal.UserAgentApplication(
environment.clientID,
this._authority,
this.msalHandler,
{
cacheLocation: 'localStorage',
redirectUri: window.location.origin
});
}
msalHandler(errorDesc: any, token: any, error: any, tokenType: any) {
let userAgent: Msal.UserAgentApplication = <any>(this);
if (errorDesc.indexOf("AADB2C90118") > -1) {
//Forgotten password
userAgent.authority = `https://login.microsoftonline.com/tfp/${environment.tenant}/${environment.passResetPolicy}`;
userAgent.loginRedirect(environment.b2cScopes);
} else if (errorDesc.indexOf("AADB2C90077") > -1) {
//Expired Token, function call from interceptor with proper context
this.logout();
}
}
addUser(): void {
if (this.isOnline()) {
this.apiService.post(this.backendRoutes.addUser).subscribe();
}
}
login(): void {
this._clientApplication.loginRedirect(environment.b2cScopes);
}
logout(): void {
this._clientApplication.logout();
}
getAuthenticationToken(): Promise<string> {
return this._clientApplication.acquireTokenSilent(environment.b2cScopes)
.then(token => token)
.catch(error => {
return Promise.reject(error);
});
}
和攔截器鏈接到它:
export class AuthenticationHttpInterceptor implements HttpInterceptor {
constructor(private authenticationService: AuthenticationService) {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return from(this.authenticationService.getAuthenticationToken()
.then(token => {
return req.clone({
setHeaders: {
Authorization: `Bearer ${token}`
}
});
})
.catch(err => {
this.authenticationService.msalHandler(err,null,null,null);
return req;
}))
.switchMap(req => {
return next.handle(req);
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.