4.0.2 • Published 6 years ago

ngx-oauth2 v4.0.2

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
6 years ago

NgxOauth2 Build Status

This module allows you to automatically be redirect to any OAuth2 SSO on 401 server response. This project was generated with Angular CLI version 6.0.0.

Installing

npm install ngx-oauth2 --save

Library usage

Basic usage

Just import the module and give him the API Management's provided clientId which allow your front application to communicate to your API.

@NgModule({
    imports: [
        ...,
        OAuth2Module.forRoot({clientId: '', loginEndpoint: ''})
    ],
    providers: [...],
    bootstrap: [AppComponent]
})
export class AppModule { }

And you just have to use the HttpClient service the regular way.

Advanced configuration

  • apiKeys?: {[urlPattern: string]: string};
  • logoutEndpoint?: string;
  • userEndpoint?: string;

OAuth2Service

  • isConnected(): boolean
  • login(): Observable<Map<string, string>>
  • logout(): Observable<{}>
  • userInfo<T>(): Observable<T>
  • token(): OAuth2Token

Guards

OAuth2ConnectedGuard

You can use this guard to activate a route only if a valid token is present in the application.

OAuth2VisitorGuard

You can use this guard to activate a route only if there isn't token in the application.

Protecting all routes in your application

The best way to protect all your application is to use the OAuth2ConnectedGuard on a global route :

export const routingTable: Routes = [
  {
    path: '',
    canActivate: [OAuth2ConnectedGuard],
    children: [
      ... // all of your application routes goes here
    ]
  }
];
4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago