The access token is invalid or has expired

Hi,

I’m using oauth2 authentication on my HTTP node. Authorization is performed, running requests until the token expires. After expiring I’m getting a 401 error, as described below.
Can someone help me?

The Error

{
   "error_description": "The access token is invalid or has expired",
   "error": "invalid_token"
},

The workflow

Information on your n8n setup

  • n8n version: 0.160.0
  • n8n.cloud

You’ll need to use the refresh_token from original authorization to refresh the token for that connection. I found some info here under Step 5 - Refresh Your Access Token

1 Like

Yes, that’s the point. The token must be updated, but this is not happening on the part of the configured oauth2 credential.

Hi @woodyalan, welcome to the community :tada:

Many OAuth2 APIs require additional query parameters to issue refresh tokens (which can then be used by n8n to refresh the OAuth2 access token). In many cases (e.g. Google or Zoho) a value of access_type=offline in the Auth URI Query Parameters field from your screenshot will do the trick.

Could you check the documentation of your API for any information on this?

Thank you @MutedJam!

By default the API that I’m using already provides the refresh token. I did a test setting up oauth2 authentication on Insomnia and the token was renewed automatically.

API Docs

Old Token

Refreshed Token

Hi @woodyalan, I wonder if Insomnia might implement some magic on its own here. Do you by any chance have a link to the documentation of the API you are using here so I can take a closer look when I have a bit of time?

@MutedJam the API documentation is here: https://developers.contaazul.com/

In this post has a mention of refresh process: OAuth2 token refreshing - #3 by M3gaFr3ak and in this point the refresh method is called n8n/NodeExecuteFunctions.ts at master · n8n-io/n8n (github.com)