Skip to content

Commit e0ad9f1

Browse files
authored
Fix generateAuthorizationUri() typedef signature (#215)
* fix generateAuthorizationUri() typedef signature * update readme include the replyObject in the generateAuthorizationUri() example --------- Co-authored-by: Kyriakos Nicola <[email protected]>
1 parent 2009b29 commit e0ad9f1

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ fastify.googleOAuth2.getNewAccessTokenUsingRefreshToken(currentAccessToken, (err
245245
});
246246
```
247247

248-
- `generateAuthorizationUri(requestObject)`: A function that returns the authorization uri. This is generally useful when you want to handle the redirect yourself in a specific route. The `requestObject` argument passes the request object to the `generateStateFunction`). You **do not** need to declare a `startRedirectPath` if you use this approach. Example of how you would use it:
248+
- `generateAuthorizationUri(requestObject, replyObject)`: A function that returns the authorization uri. This is generally useful when you want to handle the redirect yourself in a specific route. The `requestObject` argument passes the request object to the `generateStateFunction`). You **do not** need to declare a `startRedirectPath` if you use this approach. Example of how you would use it:
249249

250250
```js
251251
fastify.get('/external', { /* Hooks can be used here */ }, async (req, reply) => {
252-
const authorizationEndpoint = fastify.customOAuth2.generateAuthorizationUri(req);
252+
const authorizationEndpoint = fastify.customOAuth2.generateAuthorizationUri(req, reply);
253253
reply.redirect(authorizationEndpoint)
254254
});
255255
```

types/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FastifyPluginCallback, FastifyRequest } from 'fastify';
1+
import { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify';
22

33
interface FastifyOauth2 extends FastifyPluginCallback<fastifyOauth2.FastifyOAuth2Options> {
44
APPLE_CONFIGURATION: fastifyOauth2.ProviderConfiguration;
@@ -127,6 +127,7 @@ declare namespace fastifyOauth2 {
127127

128128
generateAuthorizationUri(
129129
request: FastifyRequest,
130+
reply: FastifyReply,
130131
): string;
131132
}
132133

types/index.test-d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ expectAssignable<ProviderConfiguration>(fastifyOauth2.VATSIM_CONFIGURATION);
8686
expectAssignable<ProviderConfiguration>(fastifyOauth2.VATSIM_DEV_CONFIGURATION);
8787
expectAssignable<ProviderConfiguration>(fastifyOauth2.EPIC_GAMES_CONFIGURATION);
8888

89-
server.get('/testOauth/callback', async request => {
89+
server.get('/testOauth/callback', async (request, reply) => {
9090
expectType<OAuth2Namespace>(server.testOAuthName);
9191

9292
expectType<OAuth2Token>(await server.testOAuthName.getAccessTokenFromAuthorizationCodeFlow(request));
@@ -128,7 +128,8 @@ server.get('/testOauth/callback', async request => {
128128
expectError<void>(server.testOAuthName.getNewAccessTokenUsingRefreshToken(token.token, {})); // error because function call does not pass a callback as second argument.
129129
}
130130

131-
expectType<string>(server.testOAuthName.generateAuthorizationUri(request));
131+
expectType<string>(server.testOAuthName.generateAuthorizationUri(request, reply));
132+
expectError<string>(server.testOAuthName.generateAuthorizationUri(request)); // error because missing reply argument
132133

133134
return {
134135
access_token: token.token.access_token,

0 commit comments

Comments
 (0)