Skip to content

Latest commit

 

History

History
105 lines (72 loc) · 1.65 KB

README.md

File metadata and controls

105 lines (72 loc) · 1.65 KB

angular2-keycloak

Native Typescript Keycloak library.

Installation

To install this library, run:

$ npm install @ebondu/angular2-keycloak --save

Development

To generate all *.js, *.js.map and *.d.ts files:

$ npm run tsc

To lint all *.ts files:

$ npm run lint

Usage

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));
     }
     ...
}

Example

See angular2-webpack-product-app

License

Apache2 © ebondu

angular2-keycloak