@narando/nest-token-refresh
v0.3.0
Published
Handle authentication to downstream services.
Downloads
25
Keywords
Readme
@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: "[email protected]",
password: "FoObArBaZ1337",
},
}),
],
providers: [APIService, TokenRefreshAxiosInterceptor],
exports: [APIService],
})
export class APIModule {}
You can also use TokenRefreshModule.registerAsync()
to dynamically load configuration.