OAuth Token Refresh icon

OAuth Token Refresh

Refresh OAuth2 access tokens and update credentials

Overview

This node is designed to refresh OAuth2 access tokens using a specified refresh token endpoint URL. It automates the process of obtaining a new access token and optionally updates the stored credentials within n8n. This is particularly useful in workflows that require continuous authenticated access to APIs where tokens expire regularly. For example, it can be used to maintain valid authentication for integrations with services like Google, Microsoft, or any OAuth2-compliant API by refreshing tokens without manual intervention.

Properties

Name Meaning
Refresh Token Endpoint URL The URL endpoint to which the refresh token request is sent to obtain a new access token.
Options A collection of optional settings:
- Store in Static Data Boolean option to store the refreshed token data in the node's static workflow data (true/false).
- Put Result in Field The name of the output JSON field where the refreshed token information will be placed (default: "newToken").

Output

The node outputs the refreshed OAuth token data in the JSON field specified by the "Put Result in Field" property (default is newToken). The structure of this output field includes:

{
  "success": true,
  "access_token": "string",       // The newly obtained access token
  "refresh_token": "string",      // The refresh token, either new or reused if not provided by the endpoint
  "expires_in": number,           // Token expiry time in seconds
  "updated_at": "ISO timestamp"   // Timestamp when the token was refreshed
}

If the option to store in static data is enabled, the same token data is also saved in the node's static workflow data for potential reuse.

Dependencies

  • Requires an API key credential to authenticate requests to the n8n internal API for updating credentials.
  • Requires OAuth2 credentials containing the current refresh token, client ID, and client secret.
  • Uses the Axios HTTP client library to perform POST and DELETE requests.
  • The node expects the refresh token endpoint to accept query parameters including the refresh token, client ID, and client secret, and to return a JSON response with at least an access_token.

Troubleshooting

  • No refresh token available in credentials: This error occurs if the OAuth2 credentials do not contain a refresh token. Ensure that the credentials are properly set up and include a valid refresh token.
  • Credential ID not found: Indicates that the node could not find the assigned OAuth2 credential ID. Verify that the correct credentials are selected and properly linked to the node.
  • HTTP request failures: If the refresh token endpoint URL is incorrect or the server is unreachable, the node will fail. Confirm the endpoint URL and network connectivity.
  • Invalid or expired client credentials: If the client ID or secret is invalid, the refresh request will fail. Check the credentials for correctness.
  • API key issues: The node requires a valid API key credential to update credentials via the n8n API. Make sure this key is valid and has appropriate permissions.

Links and References

Discussion