Skip to content
This repository has been archived by the owner on Mar 21, 2020. It is now read-only.
/ ngx-oauth2 Public archive

This module allows you to automatically be redirect to any OAuth2 SSO on 401 server response.

License

Notifications You must be signed in to change notification settings

ChamNouki/ngx-oauth2

Repository files navigation

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 client_id which allow your front application to communicate to your API, and the url of the discovery endpoint of your OpenId SSO.

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

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

Advanced configuration

This module configuration follow the OpenId connect meta-data convention. So you can specify or override any configuration.

Keep in mind that the module require at least the authorization_endpoint config value, and optionally the userinfo_endpoint to retrieve user information.

OAuth2Service

  • isConnected(): boolean
  • login(): Observable<void | OpenIdUser>
  • logout(): Observable<void>
  • userInfo<OpenIdUser>(): Observable<T>
  • getAuthorizationHeader(): string

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
    ]
  }
];

About

This module allows you to automatically be redirect to any OAuth2 SSO on 401 server response.

Resources

License

Stars

Watchers

Forks

Packages

No packages published