• Version 0.2.3
  • Published
  • No dependencies
  • MIT license


npm i angular2-jwt
yarn add angular2-jwt
pnpm add angular2-jwt


Helper library for handling JWTs in Angular 2+




const AUTH_PROVIDERS: any[];


    function provideAuth

    provideAuth: (config?: IAuthConfigOptional) => Provider[];

      function tokenNotExpired

      tokenNotExpired: (tokenName?: string, jwt?: string) => boolean;
      • Checks for presence of token and that token hasn't expired. For use with the router decorator and NgIf


      class AuthConfig

      class AuthConfig {}
      • Sets up the authentication configuration.


      constructor(config?: IAuthConfigOptional);

        method getConfig

        getConfig: () => IAuthConfig;

          class AuthConfigConsts

          class AuthConfigConsts {}

            property DEFAULT_HEADER_NAME

            static DEFAULT_HEADER_NAME: string;

              property DEFAULT_TOKEN_NAME

              static DEFAULT_TOKEN_NAME: string;

                property HEADER_PREFIX_BEARER

                static HEADER_PREFIX_BEARER: string;

                  class AuthHttp

                  class AuthHttp {}
                  • Allows for explicit authenticated HTTP requests.


                  constructor(options: AuthConfig, http: any, defOpts?: any);

                    property tokenStream

                    tokenStream: any;

                      method delete

                      delete: (url: string, options?: any) => any;

                        method get

                        get: (url: string, options?: any) => any;

                          method head

                          head: (url: string, options?: any) => any;

                            method options

                            options: (url: string, options?: any) => any;

                              method patch

                              patch: (url: string, body: any, options?: any) => any;

                                method post

                                post: (url: string, body: any, options?: any) => any;

                                  method put

                                  put: (url: string, body: any, options?: any) => any;

                                    method request

                                    request: (url: string | Request, options?: any) => any;

                                      method requestWithToken

                                      requestWithToken: (req: any, token: string) => any;

                                        method setGlobalHeaders

                                        setGlobalHeaders: (
                                        headers: Array<Object>,
                                        request: Request | RequestOptionsArgs
                                        ) => void;

                                          class AuthHttpError

                                          class AuthHttpError extends Error {}

                                            class AuthModule

                                            class AuthModule {}
                                            • Module for angular2-jwt


                                              • @experimental


                                            constructor(parentModule: AuthModule);

                                              method forRoot

                                              static forRoot: (config: AuthConfig) => any;

                                                class JwtHelper

                                                class JwtHelper {}
                                                • Helper class to decode and find JWT expiration.

                                                method decodeToken

                                                decodeToken: (token: string) => any;

                                                  method getTokenExpirationDate

                                                  getTokenExpirationDate: (token: string) => Date;

                                                    method isTokenExpired

                                                    isTokenExpired: (token: string, offsetSeconds?: number) => boolean;

                                                      method urlBase64Decode

                                                      urlBase64Decode: (str: string) => string;


                                                        interface IAuthConfig

                                                        interface IAuthConfig {}

                                                          property globalHeaders

                                                          globalHeaders: Array<Object>;

                                                            property headerName

                                                            headerName: string;

                                                              property headerPrefix

                                                              headerPrefix: string;

                                                                property noClientCheck

                                                                noClientCheck: boolean;

                                                                  property noJwtError

                                                                  noJwtError: boolean;

                                                                    property noTokenScheme

                                                                    noTokenScheme?: boolean;

                                                                      property tokenGetter

                                                                      tokenGetter: () => string | Promise<string>;

                                                                        property tokenName

                                                                        tokenName: string;

                                                                          interface IAuthConfigOptional

                                                                          interface IAuthConfigOptional {}

                                                                            property globalHeaders

                                                                            globalHeaders?: Array<Object>;

                                                                              property headerName

                                                                              headerName?: string;

                                                                                property headerPrefix

                                                                                headerPrefix?: string;

                                                                                  property noClientCheck

                                                                                  noClientCheck?: boolean;

                                                                                    property noJwtError

                                                                                    noJwtError?: boolean;

                                                                                      property noTokenScheme

                                                                                      noTokenScheme?: boolean;

                                                                                        property tokenGetter

                                                                                        tokenGetter?: () => string | Promise<string>;

                                                                                          property tokenName

                                                                                          tokenName?: string;

                                                                                            Package Files (1)

                                                                                            Dependencies (0)

                                                                                            No dependencies.

                                                                                            Dev Dependencies (24)

                                                                                            Peer Dependencies (3)


                                                                                            To add a badge like this badgeto your package's README, use the codes available below.

                                                                                            You may also use to create a custom badge linking to

                                                                                            • Markdown
                                                                                            • HTML
                                                                                              <a href=""><img src="" alt=""></a>