https://github.com/neroniaky/angular2-token
:key: Token based authentication service for Angular with interceptor and multi-user support. Works best with devise token auth for Rails. Example:
https://github.com/neroniaky/angular2-token
angular auth authentication devise devise-token-auth interceptor interceptors oauth rails signin token
Last synced: 5 days ago
JSON representation
:key: Token based authentication service for Angular with interceptor and multi-user support. Works best with devise token auth for Rails. Example:
- Host: GitHub
- URL: https://github.com/neroniaky/angular2-token
- Owner: neroniaky
- License: mit
- Created: 2016-08-09T07:10:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-22T14:49:04.000Z (about 1 year ago)
- Last Synced: 2025-04-12T03:08:34.754Z (9 days ago)
- Topics: angular, auth, authentication, devise, devise-token-auth, interceptor, interceptors, oauth, rails, signin, token
- Language: TypeScript
- Homepage: https://stackblitz.com/github/neroniaky/angular-token
- Size: 3.17 MB
- Stars: 369
- Watchers: 29
- Forks: 186
- Open Issues: 49
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-angular-components - angular2-token - Token based authentication service for Angular2 (ng2) with multi-user support. Works best with the devise token auth gem for Rails. (Uncategorized / Uncategorized)
- awesome-angular-components - angular2-token - Token based authentication service for Angular2 (ng2) with multi-user support. Works best with the devise token auth gem for Rails. (Uncategorized / Uncategorized)
- awesome-ionic2-components - Auth with Token
README

[](https://badge.fury.io/js/angular-token)
[](https://npmjs.org/angular-token)
[](https://travis-ci.org/neroniaky/angular-token)
[](https://angular.io/styleguide)🔑 Token based authentication service for Angular with interceptor and multi-user support. Works best with the [devise token auth](https://github.com/lynndylanhurley/devise_token_auth) gem for Rails.
👋 This library has been renamed to **Angular-Token**! Please follow the [migration guide](https://angular-token.gitbook.io/docs/migrate-to-7).
---
### Quick Links
- 🚀 View to demo on [Stackblitz](https://stackblitz.com/github/neroniaky/angular-token)
- ✨ Learn about it on the [docs site](https://angular-token.gitbook.io/docs)
- 🔧 Support us by [contributing](https://angular-token.gitbook.io/docs/contribute)---
## Install
0. Set up a Rails with [Devise Token Auth](https://github.com/lynndylanhurley/devise_token_auth)1. Install Angular-Token via NPM with
```bash
npm install angular-token
```2. Import and add `AngularTokenModule` to your main module and call the 'forRoot' function with the config. Make sure you have `HttpClientModule` imported too.
```javascript
import { AngularTokenModule } from 'angular-token';@NgModule({
imports: [
...,
HttpClientModule,
AngularTokenModule.forRoot({
...
})
],
declarations: [ ... ],
bootstrap: [ ... ]
})
```3. (Maybe Optional) Fix injection context runtime error
After installing this package, if you get an `Error: inject() must be called from an injection context` when running your app, add the following to your typescript path config in the `tsconfig[.app].json` file:
```json
"paths": {
"@angular/*": [ "./node_modules/@angular/*" ]
}
```## Use
1. Register your user
```javascript
constructor(private tokenService: AngularTokenService) { }this.tokenService.registerAccount({
login: '[email protected]',
password: 'secretPassword',
passwordConfirmation: 'secretPassword'
}).subscribe(
res => console.log(res),
error => console.log(error)
);
```2. Sign in your user
```javascript
constructor(private tokenService: AngularTokenService) { }this.tokenService.signIn({
login: '[email protected]',
password: 'secretPassword'
}).subscribe(
res => console.log(res),
error => console.log(error)
);
```3. Now you can use HttpClient to access private resources
```javascript
constructor(http: HttpClient) { }this.http.get('private_resource').subscribe(
res => console.log(res),
error => console.log(error)
);
```## Contributors
| [
Jan-Philipp Riethmacher](https://github.com/neroniaky) | [
Arjen Brandenburgh](https://github.com/arjenbrandenburgh)
| :---: | :---: |### License
The MIT License (see the [LICENSE](https://github.com/neroniaky/angular-token/blob/master/LICENSE) file for the full text)