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

angular2-jwt

> 前端框架
开源

用于在 Angular 应用中处理 JWT 的辅助库

2.6K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

用于在 Angular 应用中处理 JWT 的辅助库

:books: [Documentation](#documentation) - :rocket: [Getting Started](#getting-started) - :computer: [API Reference](#api-reference) - :speech_balloon: [Feedback](#feedback) ## Documentation - [Examples](https://github.com/auth0/angular2-jwt/blob/main/EXAMPLES.md) - code samples for common angular-jwt authentication scenario's. - [Docs site](https://www.auth0.com/docs) - explore our docs site and learn more about Auth0. This library provides an `HttpInterceptor` which automatically attaches a [JSON Web Token](https://jwt.io) to `HttpClient` requests. This library does not have any functionality for (or opinion about) implementing user authentication and retrieving JWTs to begin with. Those details will vary depending on your setup, but in most cases, you will use a regular HTTP request to authenticate your users and then save their JWTs in local storage or in a cookie if successful. ## Getting started ### Requirements This project only supports the [actively supported versions of Angular as stated in the Angular documentation](https://angular.io/guide/releases#actively-supported-versions). Whilst other versions might be compatible they are not actively supported ### Installation ```bash # installation with npm npm install @auth0/angular-jwt # installation with yarn yarn add @auth0/angular-jwt ``` ## Configure the SDK Import the `JwtModule` module and add it to your imports list. Call the `forRoot` method and provide a `tokenGetter` function. You must also add any domains to the `allowedDomains`, that you want to make requests to by specifying an `allowedDomains` array. Be sure to import the `HttpClientModule` as well. ```ts import { JwtModule } from "@auth0/angular-jwt"; import { HttpClientModule } from "@angular/common/http"; export function tokenGetter() { return localStorage.getItem("access_token"); } @NgModule({ bootstrap: [AppComponent], imports: [ // ... HttpClientModule, JwtModule.forRoot({ config: { tokenGetter: tokenGetter, allowedDomains: ["example.com"], disallowedRoutes: ["http://example.com/examplebadroute/"], }, }), ], }) export class AppModule {} ``` Any requests sent using Angular's `HttpClient` will automatically have a token attached as an `Authorization` header. ```ts import { HttpClient } from "@angular/common/http"; export class AppComponent { constructor(public http: HttpClient) {} ping() { this.http.get("http://example.com/api/things").subscribe( (data) => console.log(data), (err) => console.log(err) ); } } ``` ## Using with Standalone Components If you are using `bootstrapApplication` to bootstrap your application using a standalone component, you will need a slightly different way to integrate our SDK: ``` … ``` As you can see, the differences are that: - The SDK's module is included trough `importProvidersFrom`. - In order to use the SDK's interceptor, `provideHttpClient` needs to be called with `withInterceptorsFromDi`. ## API reference Read [our API reference](https://github.com/auth0/angular2-jwt/blob/main/API.md) to get a better understanding on how to use this SDK. ## Feedback ### Contributing We appreciate feedback and contribution to this repo! Before you get started, please see the following: - [Auth0's general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md) - [Auth0's code of conduct guidelines](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md) - [This repo's contribution guide](https://github.com/auth0/angular2-jwt/blob/main/CONTRIBUTING.md) ### Raise an issue To provide feedback or report a bug, please [raise an issue on our issue tracker](https://github.com/auth0/angular2-jwt/issues). ### Vulnerability Reporting Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/responsible-disclosure-policy) details the procedure for disclosing security issues. ---

Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?

This project is licensed under the MIT license. See the LICENSE file for more info.

GitHub Issues· 0 开放

在 GitHub 查看全部

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

> 标签

TypeScriptangulardx-sdkjwt

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

> 工具信息

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

> 相关工具

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