Fixed token handling for cases where options is null
This commit is contained in:
parent
5b1b63e364
commit
cab9740221
2 changed files with 8 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
import {Injectable} from "@angular/core";
|
import {Injectable} from "@angular/core";
|
||||||
import {Http, Request, ConnectionBackend, RequestOptions, RequestOptionsArgs, Response} from "@angular/http";
|
import {Http, Request, ConnectionBackend, RequestOptions, RequestOptionsArgs, Response, Headers} from "@angular/http";
|
||||||
|
|
||||||
import {KeycloakService} from "./keycloak.service";
|
import {KeycloakService} from "./keycloak.service";
|
||||||
import {Observable} from 'rxjs/Rx';
|
import {Observable} from 'rxjs/Rx';
|
||||||
|
@ -14,6 +14,7 @@ export class KeycloakHttp extends Http {
|
||||||
}
|
}
|
||||||
|
|
||||||
private setToken(options: RequestOptionsArgs) {
|
private setToken(options: RequestOptionsArgs) {
|
||||||
|
|
||||||
if (options == null || KeycloakService.auth == null || KeycloakService.auth.authz == null || KeycloakService.auth.authz.token == null) {
|
if (options == null || KeycloakService.auth == null || KeycloakService.auth.authz == null || KeycloakService.auth.authz.token == null) {
|
||||||
console.log("Need a token, but no token is available, not setting bearer token.");
|
console.log("Need a token, but no token is available, not setting bearer token.");
|
||||||
return;
|
return;
|
||||||
|
@ -26,6 +27,11 @@ export class KeycloakHttp extends Http {
|
||||||
let tokenPromise:Promise<string> = this._keycloakService.getToken();
|
let tokenPromise:Promise<string> = this._keycloakService.getToken();
|
||||||
let tokenObservable:Observable<string> = Observable.fromPromise(tokenPromise);
|
let tokenObservable:Observable<string> = Observable.fromPromise(tokenPromise);
|
||||||
let tokenUpdateObservable:Observable<any> = Observable.create((observer) => {
|
let tokenUpdateObservable:Observable<any> = Observable.create((observer) => {
|
||||||
|
if (options == null) {
|
||||||
|
let headers = new Headers();
|
||||||
|
options = new RequestOptions({ headers: headers });
|
||||||
|
}
|
||||||
|
|
||||||
this.setToken(options);
|
this.setToken(options);
|
||||||
observer.next();
|
observer.next();
|
||||||
observer.complete();
|
observer.complete();
|
||||||
|
|
Loading…
Reference in a new issue