New OAuth2 access token is not saved

Hello,

I’m using the Exact Online API with OAuth2 (https://support.exactonline.com/community/s/knowledge-base#All-All-DNO-Content-gettingstarted).

The OAuth2 flow is working, until a token needs to be refreshed. As you can see in this image I do multiple requests to the Exact API, authorised with OAuth2:

https://drive.google.com/file/d/18eZB0AJs7DqxJKgg3_MbyxrJs3YhBNwr/view?usp=sharing

When an access token is expired, it successfully refreshes the token in the first request. But in the second request, I get this error:

{
    "status": "rejected",
    "reason": {
        "body": {
            "error": "unauthorized_client",
            "error_description": "Old refresh token used."
        },
        "code": "EAUTH"
    }
}

It looks like it is trying to refresh the token for a second time, so it seems like the new access token received in the first refresh request is not saved properly yet before the second request starts.
After I restart the workflow it successfully runs the whole workflow.

This behaviour makes it impossible to run the workflow as a cron job.

Can you please help me resolve this?

Thanks a lot!

Are the requests happening on one node or on two different ones?

Hi @jan ,

The requests are happening in two different nodes. If you look at this screenshot, in the green circled one the refresh token is successfully requested, the red circled one throws the error: https://drive.google.com/file/d/1Wga9ZQJV9ehDeSgQjD5i16g204Lm0SjU/view?usp=sharing

Ah OK, then it sadly makes sense. That is a known issue. A fix got already implemented here:

It does however require a change in literally every node. This PR does that but there are sadly also a lot of other nodes of other people out there. So before we make this breaking change did we want to see if we can bundle some breaking changes together to not having to break things multiple times. For that reason do I have currently sadly no ETA on when it will be merged.

Do you run n8n via Docker? Because then you could easily build an own image with that fix included.

Build very fast a docker-image from that branch: n8nio/n8n:load-creds-db

You can see if that fixes your problem. This image is however currently untested and will not be updated.