diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/app/app.module.ts b/examples/demo-template/angular2-product-app/src/main/webapp/app/app.module.ts index b7474892bb..fd6075fbd9 100644 --- a/examples/demo-template/angular2-product-app/src/main/webapp/app/app.module.ts +++ b/examples/demo-template/angular2-product-app/src/main/webapp/app/app.module.ts @@ -29,4 +29,4 @@ import {KeycloakHttp} from "./keycloak.http"; ], bootstrap: [ AppComponent ] }) -export class AppModule {} +export class AppModule {} \ No newline at end of file diff --git a/examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.http.ts b/examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.http.ts index 84e09b1d57..40e2f63bb3 100644 --- a/examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.http.ts +++ b/examples/demo-template/angular2-product-app/src/main/webapp/app/keycloak.http.ts @@ -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'; @@ -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; @@ -26,6 +27,11 @@ export class KeycloakHttp extends Http { let tokenPromise:Promise = this._keycloakService.getToken(); let tokenObservable:Observable = Observable.fromPromise(tokenPromise); let tokenUpdateObservable:Observable = Observable.create((observer) => { + if (options == null) { + let headers = new Headers(); + options = new RequestOptions({ headers: headers }); + } + this.setToken(options); observer.next(); observer.complete();