本文整理汇总了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);
}