Manual setting of "state" variable (oauth2)


Currently I’m trying to add an api using oauth2, however this service requires me to use a user specific identification string inside the “state” variable. How could I do this? I have already tried to manually specify a state variable in the server.js file which got me a bit further but now the OAuth2 callback state is invalid. (Server.js:830).

Thanks in advance.


Welcome to the community.

@jb2210 Try adding it to the Auth URI Query Parameters. Check the image below:

thanks for the fast reply!

I also already tried this, however n8n seems to first take its own value and then overwrite the whole thing with &state={provided state}

which result in the following error:
“Invalid state format returned”

I am able to obtain the access code manually, is there any way I could enter it manually?

I see. Then the state field will have to be added to the credentials. Will add it to my TODO list.

If you have the access token, you can add it directly to the HTTP Request Node in the authorization header, but this will work until the token expires.

1 Like

Awesome, Thanks for your time!

I will work around it using that method, thanks!

@RicardoE105 can I use the OAuth2 API credential for the “Client Credentials” flow, where the app gets a token, non interactively, from the server and uses it to access an API?

You might do that, but it will not work anymore when the token expired (usually every hour).

Thanks for the reply!
Do you see any alternative, from the available n8n credentials, that does that? Picks the “expires_in” variable from the response and automatically updates the token?

In the service you are trying to use, how often the token expires?

about every 10 hours