Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update README.md with revised information #207

Merged
merged 4 commits into from
Jun 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fastify.get('/login/facebook/callback', async function (request, reply) {
console.log(token.access_token)

// if later you need to refresh the token you can use
// const { token: newToken } = await this.getNewAccessTokenUsingRefreshToken(token.refresh_token)
// const { token: newToken } = await this.getNewAccessTokenUsingRefreshToken(token)

reply.send({ access_token: token.access_token })
})
Expand Down Expand Up @@ -227,7 +227,14 @@ This fastify plugin adds 3 utility decorators to your fastify instance using the
- `refresh_token` (optional, only if the `offline scope` was originally requested, as seen in the callbackUriParams example)
- `token_type` (generally `'bearer'`)
- `expires_in` (number of seconds for the token to expire, e.g. `240000`)
- `getNewAccessTokenUsingRefreshToken(refreshToken, params, callback)`: A function that takes a refresh token and retrieves a new `AccessToken` object. This is generally useful with background processing workers to re-issue a new token when the original token has expired. The `params` argument is optional and it is an object that can be used to pass in extra parameters to the refresh request (e.g. a stricter set of scopes). If the callback is not passed this function will return a promise. The object resulting from the callback call or the promise resolution is a new `AccessToken` object (see above).
- `getNewAccessTokenUsingRefreshToken(AccessToken, params, callback)`: A function that takes a AccessToken and retrieves a new `AccessToken` object. This is generally useful with background processing workers to re-issue a new token when the original token has expired. The `params` argument is optional and it is an object that can be used to pass in extra parameters to the refresh request (e.g. a stricter set of scopes). If the callback is not passed this function will return a promise. The object resulting from the callback call or the promise resolution is a new `AccessToken` object (see above). Example of how you would use it for `name:googleOAuth2`:
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
-
rojandahal marked this conversation as resolved.
Show resolved Hide resolved
```js
fastify.googleOAuth2.getNewAccessTokenUsingRefreshToken(accessToken,(err, accessToken) => {
//Handle new accessToken
});
rojandahal marked this conversation as resolved.
Show resolved Hide resolved
```

- `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:

```js
Expand Down