本文整理匯總了TypeScript中angular-oauth2-oidc.OAuthService.getAccessToken方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript OAuthService.getAccessToken方法的具體用法?TypeScript OAuthService.getAccessToken怎麽用?TypeScript OAuthService.getAccessToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類angular-oauth2-oidc.OAuthService
的用法示例。
在下文中一共展示了OAuthService.getAccessToken方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: isLoggedIn
isLoggedIn(){
console.log(this.oauthService.getAccessToken());
if (this.oauthService.getAccessToken() === null){
return false;
}
return true;
}
示例2: getResource
getResource(resourceUrl) : Observable<Foo>{
var headers = new Headers({'Content-type': 'application/x-www-form-urlencoded; charset=utf-8', 'Authorization': 'Bearer '+this.oauthService.getAccessToken()});
var options = new RequestOptions({ headers: headers });
return this._http.get(resourceUrl, options)
.map((res:Response) => res.json())
.catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}
示例3: getResource
getResource(resourceUrl) : Observable<any>{
var headers = new HttpHeaders({'Content-type': 'application/x-www-form-urlencoded; charset=utf-8', 'Authorization': 'Bearer '+this.oauthService.getAccessToken()});
return this._http.get(resourceUrl, { headers: headers })
.catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}
示例4: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.oauthService = this.injector.get(OAuthService);
const token = this.oauthService.getAccessToken() || '';
const cloneReq = req.clone({headers: req.headers.set("X-Auth-Token", token)});
return next.handle(cloneReq);
}