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:
安全与隐私实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文
🔑 Token based authentication service for Angular with interceptor and multi-user support. Works best with the devise token auth gem for Rails.
👋 This library has been renamed to Angular-Token! Please follow the migration guide.
Quick Links
- 🚀 View to demo on Stackblitz
- ✨ Learn about it on the docs site
- 🔧 Support us by contributing
Install
Set up a Rails with Devise Token Auth
Install Angular-Token via NPM with
npm install angular-tokenImport and add
AngularTokenModuleto your main module and call the 'forRoot' function with the config. Make sure you haveHttpClientModuleimported too.import { AngularTokenModule } from 'angular-token'; @NgModule({ imports: [ ..., HttpClientModule, AngularTokenModule.forRoot({ ... }) ], declarations: [ ... ], bootstrap: [ ... ] })(Maybe Optional) Fix injection context runtime error After installing this package, if you get an
Error: inject() must be called from an injection contextwhen running your app, add the following to your typescript path config in thetsconfig[.app].jsonfile:"paths": { "@angular/*": [ "./node_modules/@angular/*" ] }
Use
Register your user
constructor(private tokenService: AngularTokenService) { } this.tokenService.registerAccount({ login: '[email protected]', 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: '[email protected]', 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) );
Contributors
Jan-Philipp Riethmacher |
Arjen Brandenburgh |
|---|
License
The MIT License (see the LICENSE file for the full text)
探索相关项目
加载中…