# Authorisation code flow: Error 403

**URL:** <https://community.auth0.com/t/authorisation-code-flow-error-403/73029>\
**Category:** Get Help\
**Created:** [November 12, 2021, 10:11am UTC](https://community.auth0.com/t/authorisation-code-flow-error-403/73029 "2021-11-12T10:11:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack.cattell](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jack.cattell/32/32753_2.png) [@jack.cattell](https://community.auth0.com/u/jack.cattell)\
**Post date:** [November 12, 2021, 10:11am UTC](https://community.auth0.com/t/authorisation-code-flow-error-403/73029/1 "2021-11-12T10:11:21Z")

</div>

Hi

I am following the Authorization Code Flow ([Call Your API Using the Authorization Code Flow (auth0.com)](https://auth0.com/docs/authorization/flows/call-your-api-using-the-authorization-code-flow)) and I receive Error 403 {“error”:“invalid\_grant”,“error\_description”:“Invalid authorization code”} when I make the token request.

I complete step 1 successfully and Auth0 generates a URL in the format:

[https://host.mydomain.com/callback?code=AUTHORIZATION\_CODE&state=STATE](https://host.mydomain.com/callback?code=AUTHORIZATION_CODE&state=STATE)

I then make the a token request using the AUTHORIZATION\_CODE from the URL:

curl --request POST \   
–url ‘[https://myusername.auth0.com/oauth/token](https://myusername.auth0.com/oauth/token)’   
–header ‘content-type: application/x-www-form-urlencoded’   
–data ‘grant\_type=authorization\_code’   
–data ‘client\_id=MY\_ID’   
–data ‘client\_secret=MY\_SECRET’   
–data ‘code=AUTHORIZATION\_CODE’   
–data ‘redirect\_uri=[https://host.mydomain.io/callback](https://host.mydomain.io/callback)’

I have checked all parameters and all are correct. All prerequisites are correct and API is authorised for the application.

Any help will be appreciated.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 12, 2021, 6:26pm UTC](https://community.auth0.com/t/authorisation-code-flow-error-403/73029/3 "2021-11-12T18:26:22Z")

</div>

Hi @jack.cattell,

Thanks for reaching out to the Auth0 Community!

I understand that you’ve encountered the _403 invalid grant and Invalid authorization code_ error when requesting the `/oauth/token` endpoint.

This error can happen for a few reasons. The provided authorization code could be invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client. This is described in the OAuth 2.0 error code specification [RFC 6749 - The OAuth 2.0 Authorization Framework](https://datatracker.ietf.org/doc/html/rfc6749#section-5.2).

I have gone ahead and tried to reproduce the error and was able to by using an expired authorization code. See below:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/d/1/d11570814277fadafac76fb5b7d0d83354da68d7.png)

Given that, I recommend that you identify whether the authorization code you used satisfies one of the reasons mentioned earlier. And then adjust your requests if needed.

Hoped this helps!

Please let me know if there’s anything else I can do to help.

Thank you.

---

<div class="post-metadata">

**Author:** ![jack.cattell](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jack.cattell/32/32753_2.png) [@jack.cattell](https://community.auth0.com/u/jack.cattell)\
**Post date:** [November 12, 2021, 7:27pm UTC](https://community.auth0.com/t/authorisation-code-flow-error-403/73029/4 "2021-11-12T19:27:12Z")

</div>

Thank you for your response.

I will check. How quickly does a code expiry (I however make the token request as soon as I receive the authorisation code)?

Could you also explain what ‘does not match the redirection URI’ means exactly? My hunch is this is more likely explanation but I am unsure what I have to check.

Jack

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 12, 2021, 8:02pm UTC](https://community.auth0.com/t/authorisation-code-flow-error-403/73029/5 "2021-11-12T20:02:24Z")

</div>

Hi @jack.cattell,

Thank you for your reply.

According to the OAuth 2.0 specification, the authorization code expires shortly after it is issued, with a maximum authorization code lifetime of 10minutes (could potentially be shorter). If you are making your requests immediately after receiving your authorization code, you can eliminate this error as a possibility.

What is meant by “does not match the redirection URI used in the authorization request” means that your `redirect_uri` parameter should match in both your `/authorize` request and `/oauth/token` request.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/0/3/03651f37f18ff32f7e9d5cacc06457415c00e429.jpeg)

If this is the case, you’ll need to make sure these values are the same.

Please let me know if you have any other questions. I’d be happy to help.

Thank you.

---

<div class="post-metadata">

**Author:** ![jack.cattell](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jack.cattell/32/32753_2.png) [@jack.cattell](https://community.auth0.com/u/jack.cattell)\
**Post date:** [November 12, 2021, 8:32pm UTC](https://community.auth0.com/t/authorisation-code-flow-error-403/73029/6 "2021-11-12T20:32:58Z")

</div>

Thanks. I will check

---

<div class="post-metadata">

**Author:** ![Riddlehouse](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/riddlehouse/32/12951_2.png) [@Riddlehouse](https://community.auth0.com/u/Riddlehouse)\
**Post date:** [November 22, 2021, 7:14pm UTC](https://community.auth0.com/t/authorisation-code-flow-error-403/73029/7 "2021-11-22T19:14:19Z")

</div>

Hi all.

I have started to get this error recently. It might be the same reason as you mention.

We are sometimes getting a code ending with a #(hashtag) first time a user authenticates with google.  
When I post it to oauth/token, it always returns a 403.  
I have tried with and without encoding the value, but it makes no difference.

Still works the second time the user gets a code (after he is added to the auth0 database). All other connections works fine (facebook, apple and email/password)

/Freddy

---

<div class="post-metadata">

**Author:** ![Riddlehouse](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/riddlehouse/32/12951_2.png) [@Riddlehouse](https://community.auth0.com/u/Riddlehouse)\
**Post date:** [November 23, 2021, 8:18am UTC](https://community.auth0.com/t/authorisation-code-flow-error-403/73029/8 "2021-11-23T08:18:15Z")

</div>

SOLVED:  
The #(hashtag) is a fragment identifier and not part of the code.

The problem here, was that our frontend parser of the URL, only considered ? and & to split parameters, so it put the fragment identifier as part of the code parameter.

Thanks,  
/Freddy

---

<div class="post-metadata">

**Author:** ![jack.cattell](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jack.cattell/32/32753_2.png) [@jack.cattell](https://community.auth0.com/u/jack.cattell)\
**Post date:** [November 23, 2021, 9:43am UTC](https://community.auth0.com/t/authorisation-code-flow-error-403/73029/9 "2021-11-23T09:43:13Z")

</div>

Hi

I updated the redirect\_uri and it worked, but then stopped working and I have the same problem now which has baffled me. Any further ideas?

jack.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 8, 2021, 9:43am UTC](https://community.auth0.com/t/authorisation-code-flow-error-403/73029/10 "2021-12-08T09:43:54Z")

</div>

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