Refreshing tokens
A refresh token is a security credential that allows client applications to obtain new access tokens without requiring users to reauthorize the application.
Access tokens are intentionally configured to have a limited lifespan (1 hour), at the end of which, new tokens can be obtained by providing the original refresh token acquired during the authorization token request response:
Request
To refresh an access token, we must send a POST
request with the following parameters:
Body Parameter | Relevance | Value |
---|---|---|
grant_type | Required | Set it to refresh_token . |
refresh_token | Required | The refresh token returned from the authorization token request. |
client_id | Only required for the PKCE extension | The client ID for your app, available from the developer dashboard. |
And the following headers:
Header Parameter | Relevance | Value |
---|---|---|
Content-Type | Required | Always set to application/x-www-form-urlencoded . |
Authorization | Only required for the Authorization Code | Base 64 encoded string that contains the client ID and client secret key. The field must have the format: Authorization: Basic <base64 encoded client_id:client_secret> |
Example
The following code snippets represent two examples:
- A client side (browser) JavaScript function to refresh tokens issued following the Authorization Code with PKCE extension flow.
- A server side (nodeJS with express) Javascript method to refresh tokens issued under the Authorization Code flow.
Response
If everything goes well, you'll receive a 200 OK
response which is very similar to the response when issuing an access token:
The refresh token contained in the response, can be used to request new tokens. Depending on the grant used to get the initial refresh token, a refresh token might not be included in each response. When a refresh token is not returned, continue using the existing token.