Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit 7773d3d

Browse files
authored
Document request scoped Octokit providers
Document the feature introduced in #3
1 parent 93e4ec3 commit 7773d3d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,38 @@ export class SomeController {
8585
}
8686
```
8787

88+
### Short-lived access tokens
89+
90+
If your access tokens are short-lived, you can configure a [request
91+
scoped](https://docs.nestjs.com/fundamentals/injection-scopes#provider-scope)
92+
Octokit provider with an `auth` callback, to renew the Octokits
93+
and auth tokens:
94+
95+
```ts
96+
import { OctokitModule } from 'nestjs-octokit';
97+
import { Scope } from '@nestjs/common';
98+
99+
@Module({
100+
imports: [
101+
OctokitModule.forRootAsync({
102+
isGlobal: true,
103+
// Set request scope
104+
octokitScope: Scope.REQUEST,
105+
imports: [TokenModule],
106+
inject: [TokenService],
107+
useFactory: async (tokenService: TokenService) => ({
108+
octokitOptions: {
109+
// `auth` is a callback now. Return short-lived tokens
110+
auth: () => tokenService.produceToken(),
111+
},
112+
}),
113+
}),
114+
// ...
115+
],
116+
})
117+
export class AppModule {}
118+
```
119+
88120
## Plugins
89121

90122
To use plugins:

0 commit comments

Comments
 (0)