An Angular HTTP interceptor library for automatically attaching JSON Web Tokens (JWTs) to HttpClient requests.
Angular2-JWT is a helper library for Angular applications that automates the process of attaching JSON Web Tokens (JWTs) to HTTP requests. It provides an `HttpInterceptor` that injects the token into the `Authorization` header of every `HttpClient` call, solving the problem of manually managing authentication headers for secure API communication.
Angular developers building applications that require authenticated API calls using JWTs, particularly those using Auth0 or similar authentication services.
Developers choose Angular2-JWT because it eliminates boilerplate code for token handling, reduces the risk of authentication errors, and integrates seamlessly with Angular's `HttpClient` while remaining unopinionated about the broader authentication flow.
Helper library for handling JWTs in Angular apps
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The HttpInterceptor seamlessly adds JWTs as Authorization headers to all HttpClient requests, eliminating manual boilerplate code, as shown in the configuration example where requests to example.com automatically include the token.
Configurable allowedDomains and disallowedRoutes let developers restrict token sending to specific endpoints, preventing unnecessary exposure, evidenced by the array-based settings in the module setup.
Supports a custom tokenGetter function to fetch tokens from any source like localStorage or cookies, making it adaptable to different storage strategies without locking into a specific implementation.
Works with both NgModule-based and standalone Angular applications, as detailed in the README's separate setup instructions for bootstrapApplication, ensuring support for current Angular practices.
Only handles token attachment, not acquisition or refresh; developers must implement the full authentication flow themselves, a limitation explicitly stated in the README's 'no authentication opinions' section.
Requires explicit setup of allowedDomains, disallowedRoutes, and tokenGetter, which can be cumbersome for simple apps compared to manually adding headers for a few API calls.
Relies entirely on Angular's HttpClient and interceptor system, making it incompatible with alternative HTTP libraries and vulnerable to breaking changes in Angular's DI or interceptor APIs.