Native Typescript Keycloak library.
To install this library, run:
$ npm install @ebondu/angular2-keycloak --save
To generate all *.js
, *.js.map
and *.d.ts
files:
$ npm run tsc
To lint all *.ts
files:
$ npm run lint
Declare Keycloak module in angular app :
import { Ng2KeycloakModule } from '@ebondu/angular2-keycloak';
...
@NgModule({
declarations: [
AppComponent
],
imports: [
Ng2KeycloakModule
],
providers: [
...
],
bootstrap: [AppComponent]
})
export class AppModule { }
To login
import { Keycloak } from '@ebondu/angular2-keycloak';
...
export class MyLoginClass {
constructor( private keycloak: Keycloak) {
this.keycloak.init({});
}
login(): void {
Keycloak.login(true);
}
...
}
To use keycloak http proxy (authentication / authorization)
import { KeycloakHttp } from '@ebondu/angular2-keycloak';
...
@Injectable()
export class MyClass {
constructor(private http: KeycloakHttp) {
}
callAPI(): Observable<MyObject> {
let headers = new Headers({'Accept' :'application/json'});
let options: RequestOptionsArgs = { headers: headers };
return this.http.get("http://localhost/myAPI/myMethod", options)
.map(res => res.json())
.catch(err => handleError(err));
}
...
}
See angular2-webpack-product-app
Apache2 © ebondu