:key: 为 Angular 提供基于令牌的身份验证服务,支持拦截器和多用户支持。与 Rails 的 devise 令牌身份验证搭配使用效果最佳。示例:
:key: 为 Angular 提供基于令牌的身份验证服务,支持拦截器和多用户支持。与 Rails 的 devise 令牌身份验证搭配使用效果最佳。示例:
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.
Set up a Rails with Devise Token Auth
Install Angular-Token via NPM with
npm install angular-tokenImport and add AngularTokenModule to your main module and call the 'forRoot' function with the config. Make sure you have HttpClientModule imported 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 context when running your app, add the following to your typescript path config in the tsconfig[.app].json file:
"paths": {
"@angular/*": [ "./node_modules/@angular/*" ]
}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)
);| Jan-Philipp Riethmacher | [
Arjen Brandenburgh](https://github.com/arjenbrandenburgh) | :---: | :---: |
The MIT License (see the LICENSE file for the full text)
暂无开放 Issues,或尚未同步最近议题。