Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/neroniaky/angular-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/angular-token

angular auth authentication devise devise-token-auth interceptor interceptors oauth rails signin token

Last synced: about 1 month 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:

Lists

README

        

![Angular-Token](https://raw.githubusercontent.com/neroniaky/angular-token/master/docs/angular-token-logo.png)

[![npm version](https://badge.fury.io/js/angular-token.svg)](https://badge.fury.io/js/angular-token)
[![npm downloads](https://img.shields.io/npm/dt/angular-token.svg)](https://npmjs.org/angular-token)
[![Build Status](https://travis-ci.org/neroniaky/angular-token.svg?branch=master)](https://travis-ci.org/neroniaky/angular-token)
[![Angular Style Guide](https://mgechev.github.io/angular2-style-guide/images/badge.svg)](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)