@narando/nest-token-refresh
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

@narando/token-refresh

Handle authentication to downstream services.

  • Add bearer tokens to outgoing http requests
  • Detect and refresh expired tokens

Getting Started

Requirements

  • NestJS 7 (6 should work but is not supported)

Installation

npm i @narando/nest-token-refresh

Configuration

With the package installed, you can now add it to any HttpService based API clients.

It is important that you import the TokenRefreshModule, and then add the TokenRefreshAxiosInterceptor to the list of the providers.

This will register the interceptor with the Axios client from HttpModule.

import {
  TokenRefreshModule,
  TokenRefreshAxiosInterceptor,
} from "@narando/nest-token-refresh";

@Module({
  imports: [
    HttpModule.register({}),
    TokenRefreshModule.register({
      apiHost: "https://api.narando.com",
      credentials: {
        username: "foo@bar.com",
        password: "FoObArBaZ1337",
      },
    }),
  ],
  providers: [APIService, TokenRefreshAxiosInterceptor],
  exports: [APIService],
})
export class APIModule {}

You can also use TokenRefreshModule.registerAsync() to dynamically load configuration.

Readme

Keywords

none

Package Sidebar

Install

npm i @narando/nest-token-refresh

Weekly Downloads

0

Version

0.3.0

License

UNLICENSED

Unpacked Size

18.9 kB

Total Files

19

Last publish

Collaborators

  • narandosystem
  • marcmogdanz
  • apricote
  • brandolpho