Skip to content

Commit

Permalink
Fixed token handling for cases where options is null
Browse files Browse the repository at this point in the history
  • Loading branch information
jsight committed Oct 3, 2016
1 parent 5b1b63e commit cab9740
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ import {KeycloakHttp} from "./keycloak.http";
],
bootstrap: [ AppComponent ]
})
export class AppModule {}
export class AppModule {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 {Observable} from 'rxjs/Rx';
Expand All @@ -14,6 +14,7 @@ export class KeycloakHttp extends Http {
}

private setToken(options: RequestOptionsArgs) {

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.");
return;
Expand All @@ -26,6 +27,11 @@ export class KeycloakHttp extends Http {
let tokenPromise:Promise<string> = this._keycloakService.getToken();
let tokenObservable:Observable<string> = Observable.fromPromise(tokenPromise);
let tokenUpdateObservable:Observable<any> = Observable.create((observer) => {
if (options == null) {
let headers = new Headers();
options = new RequestOptions({ headers: headers });
}

this.setToken(options);
observer.next();
observer.complete();
Expand Down

0 comments on commit cab9740

Please sign in to comment.