0.3.0 • Published 4 years ago

@narando/nest-token-refresh v0.3.0

Weekly downloads
191
License
UNLICENSED
Repository
-
Last release
4 years ago

@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.