# New OAuth2 access token is not saved

**URL:** <https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743>\
**Category:** Questions\
**Tags:** credentials\
**Created:** [May 13, 2021, 8:17am UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743 "2021-05-13T08:17:57Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![freddie](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/freddie/32/1386_2.png) [@freddie](https://community.n8n.io/u/freddie)\
**Post date:** [May 13, 2021, 8:17am UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/1 "2021-05-13T08:17:58Z")

</div>

Hello,

I’m using the Exact Online API with OAuth2 ([support](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](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!

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [May 13, 2021, 2:33pm UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/2 "2021-05-13T14:33:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![freddie](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/freddie/32/1386_2.png) [@freddie](https://community.n8n.io/u/freddie)\
**Post date:** [May 14, 2021, 6:11am UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/3 "2021-05-14T06:11:42Z")

</div>

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](https://drive.google.com/file/d/1Wga9ZQJV9ehDeSgQjD5i16g204Lm0SjU/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [May 14, 2021, 7:56pm UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/4 "2021-05-14T19:56:15Z")

</div>

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

> <https://github.com/n8n-io/n8n/pull/1741>
>
> This pull request relates to issue https://github.com/n8n-io/n8n/issues/1695
> 
> …We changed the way n8n uses credentials for nodes by loading them from database on demand always.
> 
> This change was made because OAuth access tokens expire eventually and by keeping tokens in memory n8n refreshes tokens too many times.
> 
> Tests that were done to certify nothing broke:
> \- Trigger, webhook and poll nodes
> \- Main, own and queue modes
> \- OAuth2 app connection (had side effect from the changes)
> 
> 
> Please feel free to share ideas for other tests that should be done.

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.

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [May 14, 2021, 10:33pm UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/5 "2021-05-14T22:33:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![freddie](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/freddie/32/1386_2.png) [@freddie](https://community.n8n.io/u/freddie)\
**Post date:** [June 24, 2021, 7:06am UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/6 "2021-06-24T07:06:37Z")

</div>

This fixed the issues for now, I hope the PR is merged soon!

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [June 24, 2021, 7:27am UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/7 "2021-06-24T07:27:36Z")

</div>

Glad to hear that it works. As it is a breaking change (on the code side) are we currently waiting on getting also another feature ready with another breaking change to not cause to many problems for users with custom nodes. Once that is ready will we release them together.

---

<div class="post-metadata">

**Author:** ![laurens-novyx](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/laurens-novyx/32/5301_2.png) [@laurens-novyx](https://community.n8n.io/u/laurens-novyx)\
**Post date:** [July 26, 2021, 9:19am UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/8 "2021-07-26T09:19:05Z")

</div>

We are unfortunately running into the same issue, also with the Exact Online API.

Is there already a time window for the release of this fix?  
It would be especially important for use in the authentication part of the ‘HTTP Request’ node.

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [August 22, 2021, 1:50pm UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/10 "2021-08-22T13:50:30Z")

</div>

Fix got released with 0.135.0

---

<div class="post-metadata">

**Author:** ![freddie](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/freddie/32/1386_2.png) [@freddie](https://community.n8n.io/u/freddie)\
**Post date:** [December 8, 2021, 10:11am UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/12 "2021-12-08T10:11:59Z")

</div>

I am using version 0.151.0, and the issue occurs again with the exact same error message:

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

```

---

<div class="post-metadata">

**Author:** ![theveloped](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/theveloped/32/13949_2.png) [@theveloped](https://community.n8n.io/u/theveloped)\
**Post date:** [June 7, 2022, 12:03pm UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/13 "2022-06-07T12:03:37Z")

</div>

Hi @freddie, very curious if you have been able to solve your issue and if you have any advice on connecting to exact online. As far as I can tell on my end the OAuth2 credentials are picked up by n8n correctly but running any request using the credentials will simply get hang on “executing node”.

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [June 7, 2022, 12:21pm UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/14 "2022-06-07T12:21:41Z")

</div>

Welcome to the community @theveloped

What version of n8n are you using?

---

<div class="post-metadata">

**Author:** ![freddie](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/freddie/32/1386_2.png) [@freddie](https://community.n8n.io/u/freddie)\
**Post date:** [June 7, 2022, 12:31pm UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/15 "2022-06-07T12:31:27Z")

</div>

Hi @theveloped, this sounds to me like another issue.  
Mine is still not resolved though, tokens are not refreshed correctly it seems.

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [June 7, 2022, 2:15pm UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/16 "2022-06-07T14:15:03Z")

</div>

Are you still using 0.151.0? Because we made a change to OAuth2 in `n8n@0.163.1`

[https://docs.n8n.io/reference/release-notes/#core-functionality\_5](https://docs.n8n.io/reference/release-notes/#core-functionality_5)

---

<div class="post-metadata">

**Author:** ![freddie](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/freddie/32/1386_2.png) [@freddie](https://community.n8n.io/u/freddie)\
**Post date:** [June 7, 2022, 2:25pm UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/17 "2022-06-07T14:25:59Z")

</div>

I am currently on 0.173.1

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [June 7, 2022, 4:27pm UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/18 "2022-06-07T16:27:39Z")

</div>

Then if it does not refresh it, Exact Online might be expecting something non-standard when refreshing the token. It isn’t easy to have an OAuth2 flow so generic that it covers all possible cases. Even though it’s a standard, some companies choose to add a minor tweak to it. This issue might solve by creating an Exact Online node because, in the node, we can use variables that change the refresh token behavior, unlike with the HTTP node. The other option would be to make the OAuth2 flow credentials more extensible to cover non-standard user cases. The latter will take a considerable amount of work.

---

<div class="post-metadata">

**Author:** ![freddie](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/freddie/32/1386_2.png) [@freddie](https://community.n8n.io/u/freddie)\
**Post date:** [June 10, 2022, 10:12am UTC](https://community.n8n.io/t/new-oauth2-access-token-is-not-saved/5743/19 "2022-06-10T10:12:43Z")

</div>

Thanks, what would be a good starting point for me to develop the Exact node?
