👋 This library has been renamed to Angular-Token! 👋
Please follow the migration guide
Token based authentication service for Angular with support for Http Interceptors and multiple user. Angular-Token works best with the devise token auth gem for Rails. Any contribution is much appreciated.
-
Set up a Rails with Devise Token Auth
-
Install Angular-Token via NPM with
npm install angular-token
-
Import and add
AngularTokenModule
to your main module and call the 'forRoot' function with the config. Make sure you haveHttpClientModule
imported too.import { AngularTokenModule } from 'angular-token'; @NgModule({ imports: [ ..., HttpClientModule, AngularTokenModule.forRoot({ ... }) ], declarations: [ ... ], providers: [ AngularTokenModule ], bootstrap: [ ... ] })
-
Register your user
constructor(private tokenService: AngularTokenService) { } this.tokenService.registerAccount({ login: 'example@example.org', password: 'secretPassword', passwordConfirmation: 'secretPassword' }).subscribe( res => console.log(res), error => console.log(error) );
-
Sign in your user
constructor(private tokenService: AngularTokenService) { } this.tokenService.signIn({ login: 'example@example.org', password: 'secretPassword' }).subscribe( res => console.log(res), error => console.log(error) );
-
Now you can use HttpClient to access private resources
constructor(http: HttpClient) { } this.http.get('private_resource').subscribe( res => console.log(res), error => console.log(error) );
In the Angular-Token Wiki you'll find lots of additional information and answers to the most frequently asked questions.
- Configuration - Customize Angular-Token.
- Session Management - Methods to handel a session (sign in, sign out etc.).
- Multiple User Types - Configure Angular-Token for multiple user types.
- Routing - Use the Angular-Token routing helpers.
- Service Methods - More advanced status methods Angular-Token provides.
- Common Problems - Commonly encountered problems.
- Development - How to contribute to Angular-Token.
Jan-Philipp Riethmacher |
Arjen Brandenburgh |
---|
The MIT License (see the LICENSE file for the full text)