From e8df9dcd7dee7ac55db5e1d9e6c4a641dff631b2 Mon Sep 17 00:00:00 2001 From: Rojan Dahal <53342953+rojandahal@users.noreply.github.com> Date: Mon, 5 Jun 2023 18:04:34 +0545 Subject: [PATCH] docs: Update README.md with revised information (#207) --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4978bad..793eeb9 100644 --- a/README.md +++ b/README.md @@ -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 }) }) @@ -227,7 +227,13 @@ 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(Token, params, callback)`: A function that takes a `AccessToken`-Object as `Token` and retrieves a new `AccessToken`-Object. This is generally useful with background processing workers to re-issue a new AccessToken when the previous AccessToken has expired. The `params` argument is optional and it is an object that can be used to pass in additional 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 resolved Promise is a new `AccessToken` object (see above). Example of how you would use it for `name:googleOAuth2`: +```js +fastify.googleOAuth2.getNewAccessTokenUsingRefreshToken(currentAccessToken, (err, newAccessToken) => { + // Handle the new accessToken +}); +``` + - `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