百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

angular-token

> 前端框架
开源

:key: 为 Angular 提供基于令牌的身份验证服务,支持拦截器和多用户支持。与 Rails 的 devise 令牌身份验证搭配使用效果最佳。示例:

367 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

: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.


Quick Links

  • View to demo on Stackblitz
  • ✨ Learn about it on the docs site
  • Support us by contributing

Install

  1. Set up a Rails with Devise Token Auth

  2. Install Angular-Token via NPM with

    bash
    npm install angular-token
  3. 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:    [ ... ]
    })
  4. (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 | [

Arjen Brandenburgh](https://github.com/arjenbrandenburgh) | :---: | :---: |

License

The MIT License (see the LICENSE file for the full text)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptangularauthauthenticationdevise

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架