Dealing with OAuth2 refresh Bearer Token

I’m trying to connect to an API in the best way possible.
They use OAuth2 and Bearer Tokens with a “expires_in: 86400” variable, meaning I have to generate a new token every day, right?

I can obtain the Bearer Token separately and simply use it with a Header Auth credential. But I probably should create an OAuth2 credential, because of the toekn refresh interval.

When trying that, I can’t find the “Authentication URL”. Only the Access Token URL.

I’ve also tried the “Client Credentails” type, but I get errors when running the node.

What is the error message (if any)?

  1. When clicking the connect account button the error is “Cannot GET /” depending on the URL I’ve used in the Authorization URL field.

  2. When using the Client Credential type, I run a node and get this error:

Information on your n8n setup

  • n8n version: 1.36.1
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: Ubuntu 22.04
2 Likes

i have exactly the same problem!

2 Likes

Yeah… I’ve faced this issue quite a few times.
We need a more experienced developer here.

1 Like

@Jon
@MutedJam

Can I kindly ask for your insights on this topic?

1 Like

Hi @solomon, I no longer work on n8n I am afraid and am just a user. I do not speak Portuguese either unfortunately, so can’t easily review the link you have shared. However, I do know that n8n tries to automatically renew OAuth2 tokens when they expire and stop working.

Based on the “rejected” response on your last screenshot without an error code I think there is a good chance the problem is within this OAuth2 flow, and not a direct response coming from the URL specified in your HTTP Request node. This in turn suggests there might be room for improvement around OAuth2 error handling and surfacing.

Until this happens I do not know what exactly is causing the error here, but I think possible next debugging steps here could be to add a lot of console.log statements to n8n’s OAuth2 code to confirm 1. exactly what request n8n is making here, and 2. what the exact response coming from your API is.

2 Likes

Thanks a lot for your reply.
If I understood correctly, there doesn’t seem to be a clear solution to this issue.

We would have to wait for further improvements from the devs?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.