# Generic Oauth: OAuth2 Authorization code was already redeemed

**URL:** <https://community.grafana.com/t/generic-oauth-oauth2-authorization-code-was-already-redeemed/154346>\
**Category:** Configuration\
**Tags:** generic-auth, api\
**Created:** [July 11, 2025, 4:30am UTC](https://community.grafana.com/t/generic-oauth-oauth2-authorization-code-was-already-redeemed/154346 "2025-07-11T04:30:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crazywalker246](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@crazywalker246](https://community.grafana.com/u/crazywalker246)\
**Post date:** [July 11, 2025, 4:30am UTC](https://community.grafana.com/t/generic-oauth-oauth2-authorization-code-was-already-redeemed/154346/1 "2025-07-11T04:30:22Z")

</div>

I am implementing the generic oauth for grafana.  
My grafana is running behind load balancer and nginx.  
I am getting error as “Failed to authenticate request” client=auth.client.generic\_oauth error=“[auth.oauth.token.exchange] failed to exchange code to token: oauth2: "invalid\_grant" "AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token.”

I can see the login.microsoft url is called twice.

first time with valid details, second time with valid details and i cansee SSO\_reload = true.

I am using Grafana v12.0.0 (4c0e7045f9)

I am using amazon linux 2023 box

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [July 15, 2025, 6:06am UTC](https://community.grafana.com/t/generic-oauth-oauth2-authorization-code-was-already-redeemed/154346/2 "2025-07-15T06:06:23Z")

</div>

I’m sorry to hear that you’re experiencing difficulties.

Grafana can provide valuable information about certain issues through its own debug logs. These logs can help troubleshoot and identify the root cause of problems (especially if they are related to anything that can be configured via Grafana config file).

To enable debug logging edit the [configuration file](https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#configure-grafana) `grafana.ini`:

```auto
[log]
# Either "console", "file", "syslog". Default is console and file
# Use space to separate multiple modes, e.g. "console file"
mode = console file

# Either "debug", "info", "warn", "error", "critical", default is "info"
level = debug

```

Then restart grafana for the setting to go into effect.

Replicate the problem and check Grafana logs. However, before posting the debug logs on the community forum, it is important to sanitize any private details such as passwords, tokens, IPs, names, … By including [properly formatted debug logs](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code) (with sanitized information) and details about your installations (e.g. exact Grafana version, how it was installed, OS details, …), you greatly enhance the chances of receiving accurate assistance and solutions.

---

<div class="post-metadata">

**Author:** ![crazywalker246](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@crazywalker246](https://community.grafana.com/u/crazywalker246)\
**Post date:** [July 22, 2025, 2:43am UTC](https://community.grafana.com/t/generic-oauth-oauth2-authorization-code-was-already-redeemed/154346/3 "2025-07-22T02:43:12Z")

</div>

Hi @jangaraj ,

Thanks for your reply. Please find the complete configuration .

I have installed grafana 12 version in a EC2 box with load balancer in front. I have Nginx configured as reverse proxy.

After enabling the Debug logs, i am getting “**Failed to authenticate request” client=auth.client.generic\_oauth error=“[auth.oauth.token.exchange] failed to exchange code to token: oauth2: “invalid\_grant” "AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token.**”

I have analysed the network calls, [login.microsoft.com/](http://login.microsoft.com/){with all our client secret, tenant id, redirect URL } is called twice.

first call has the URL with all the details and the second call has the URL ending with &sso\_reload=true.  
I feel the URL is called twice, which tries to use the TOKEN twice.. which results in the above error.

I am not able to stop the second API call.

Kindly let me know for further information

---

<div class="post-metadata">

**Author:** ![alexeykotukhovextern](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@alexeykotukhovextern](https://community.grafana.com/u/alexeykotukhovextern)\
**Post date:** [August 1, 2025, 3:00pm UTC](https://community.grafana.com/t/generic-oauth-oauth2-authorization-code-was-already-redeemed/154346/4 "2025-08-01T15:00:10Z")

</div>

Hi guys,  
I have the same issue.

Is there any solution or suggestions?

Thank you in advance.
