GitPedia

Angular2 jwt

Helper library for handling JWTs in Angular apps

From auth0·Updated June 8, 2026·View on GitHub·

:books: [Documentation](#documentation) - :rocket: [Getting Started](#getting-started) - :computer: [API Reference](#api-reference) - :speech_balloon: [Feedback](#feedback) The project is written primarily in TypeScript, distributed under the MIT License license, first published in 2015. It has gained significant community traction with 2,628 stars and 471 forks on GitHub. Key topics include: angular, dx-sdk, jwt.

Latest release: v5.2.0
October 31, 2023View Changelog →

Helper library for handling JWTs in Angular applications

Release
codecov
Ask DeepWiki
Downloads
License
CircleCI

:books: Documentation - :rocket: Getting Started - :computer: API Reference - :speech_balloon: Feedback

Documentation

  • Examples - code samples for common angular-jwt authentication scenario's.
  • Docs site - explore our docs site and learn more about Auth0.

This library provides an HttpInterceptor which automatically attaches a JSON Web Token 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. 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:

ts
import { JwtModule } from "@auth0/angular-jwt"; import { provideHttpClient, withInterceptorsFromDi } from "@angular/common/http"; export function tokenGetter() { return localStorage.getItem("access_token"); } bootstrapApplication(AppComponent, { providers: [ // ... importProvidersFrom( JwtModule.forRoot({ config: { tokenGetter: tokenGetter, allowedDomains: ["example.com"], disallowedRoutes: ["http://example.com/examplebadroute/"], }, }), ), provideHttpClient( withInterceptorsFromDi() ), ], });

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

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.

Vulnerability Reporting

Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.


<p align="center"> <picture> <source media="(prefers-color-scheme: light)" srcset="https://cdn.auth0.com/website/sdks/logos/auth0_light_mode.png" width="150"> <source media="(prefers-color-scheme: dark)" srcset="https://cdn.auth0.com/website/sdks/logos/auth0_dark_mode.png" width="150"> <img alt="Auth0 Logo" src="https://cdn.auth0.com/website/sdks/logos/auth0_light_mode.png" width="150"> </picture> </p> <p align="center">Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout <a href="https://auth0.com/why-auth0">Why Auth0?</a></p> <p align="center"> This project is licensed under the MIT license. See the <a href="https://github.com/auth0/angular2-jwt/blob/main/LICENSE"> LICENSE</a> file for more info.</p>

Contributors

Showing top 12 contributors by commit count.

View all contributors on GitHub →

This article is auto-generated from auth0/angular2-jwt via the GitHub API.Last fetched: 6/28/2026