I am running into a problem where when i try to connect to Google, using nodes like Google Cloud Storage or even using HTTP node with Oauth2, the executions will time out and either say something about a “refresh token” or “socket hang up” error.
The weird part is that if I go into my credentials and click the “Sign into Google” button, then the node works perfectly. But that only lasts a short time and then it’s back to “refresh token” and “socket hang up” errors. So, I know it works, but for some reason the authentification/credential doesn’t stick for long.
Below are screenshots of the error and then of the node working a couple seconds later after clicking the “Sign in with Google” button again…
Does anyone have a solution to this so that the credentials stick?
Google OAuth2 Token Expiration & Refresh Token Missing
Google issues access tokens that expire after 1 hour.
If the refresh token is missing or revoked, n8n cannot refresh the access token, causing failures after a short time.
Re-signing in manually temporarily fixes the issue because a new access token is generated.
Google OAuth2 Scopes Are Not Persisting
If Google’s OAuth2 consent screen was not configured properly, the refresh token might not be issued persistently.
Some Google services only issue refresh tokens on the first authentication attempt.
If you re-authenticate frequently without fully revoking previous sessions, Google may revoke old refresh tokens.
n8n Credential Storage Issue
If n8n is running in Docker or a restricted environment, credential persistence might not be working correctly.
Verify that the database storing credentials is not resetting or failing to persist refresh tokens.
Google API Quotas or Revocations
If you’re hitting Google API quota limits, Google may reject token refresh requests.
Check Google Cloud OAuth2 settings to see if your client ID is being flagged.
Solutions & Fixes
Ensure OAuth2 Refresh Token is Persisting
Delete and Recreate Google Credentials in n8n
Go to n8n Settings > Credentials.
Delete the Google OAuth2 credentials.
Click Add new credential > Google OAuth2 and re-authenticate.
Make sure to check the “Allow offline access” option.
Ensure Google Cloud Project is Configured Correctly
Visit Google Cloud Console OAuth2.
Select your OAuth2 Client ID.
Ensure “Use in Web Application” is enabled and “Authorized Redirect URIs” includes: https://n8n.yourdomain.com/rest/oauth2-credential/callback
(Adjust this URL if self-hosted with a custom domain)