本文整理匯總了TypeScript中angular-auth-oidc-client.OidcSecurityService.getToken方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript OidcSecurityService.getToken方法的具體用法?TypeScript OidcSecurityService.getToken怎麽用?TypeScript OidcSecurityService.getToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類angular-auth-oidc-client.OidcSecurityService
的用法示例。
在下文中一共展示了OidcSecurityService.getToken方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (req.url.startsWith(environment.api)) {
const token = this.oidcSecurityService.getToken();
if (token !== '') {
const tokenValue = 'Bearer ' + token;
return next.handle(req.clone({
setHeaders: {
'Authorization': tokenValue
}
}));
}
}
return next.handle(req);
}
示例2: intercept
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
let requestToForward = req;
if (this.oidcSecurityService === undefined) {
this.oidcSecurityService = this.injector.get(OidcSecurityService);
}
if (this.oidcSecurityService !== undefined) {
const token = this.oidcSecurityService.getToken();
if (token !== '') {
const tokenValue = 'Bearer ' + token;
requestToForward = req.clone({
setHeaders: { 'Authorization': tokenValue }
});
}
} else {
console.log('OidcSecurityService undefined: NO auth header!');
}
return next.handle(requestToForward);
}