# Invalid authorization code axios POST request

**URL:** <https://discuss.dev.twitch.com/t/invalid-authorization-code-axios-post-request/42864>\
**Category:** API\
**Created:** [January 17, 2023, 8:09am UTC](https://discuss.dev.twitch.com/t/invalid-authorization-code-axios-post-request/42864 "2023-01-17T08:09:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DuckenScott](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/duckenscott/32/18031_2.png) [@DuckenScott](https://discuss.dev.twitch.com/u/DuckenScott)\
**Post date:** [January 17, 2023, 8:09am UTC](https://discuss.dev.twitch.com/t/invalid-authorization-code-axios-post-request/42864/1 "2023-01-17T08:09:28Z")

</div>

Hello there,

I’m trying to get my authorization code with an axios POST call in JS, with all the good parameters sended to this url : [https://id.twitch.tv/oauth2/token](https://id.twitch.tv/oauth2/token).  
But I’ve got this error as response :  
 ![image](https://d2opxh93rbxzdn.cloudfront.net/original/3X/6/8/68307ae50498bdee644f565c24e4e409ceeeb7f8.png)

I’ve already get my code in this URL : [https://id.twitch.tv/oauth2/authorize](https://id.twitch.tv/oauth2/authorize)

Here is my JS code :  
 ![Screenshot-2023-01-17-081611](https://d2opxh93rbxzdn.cloudfront.net/original/3X/b/6/b6011e1ae67d2d1e549026cc866e1f1ba7d82d09.png)

I really don’t know here is the problem…

Thanks for help ! 🙂

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 17, 2023, 9:10am UTC](https://discuss.dev.twitch.com/t/invalid-authorization-code-axios-post-request/42864/2 "2023-01-17T09:10:01Z")

</div>

This likely indicates that the `code` which is a one use `code` has already been used to be exchanged for an access code.

Since you have this hardcoded rather than fetching it from query string parameters.

Addititionally your JS code indicates (`DomContentLoaded`) that you appear to be doing a `code` to `token` exchange in the front end, which will leak you private `client_secret` to the world.

---

<div class="post-metadata">

**Author:** ![DuckenScott](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/duckenscott/32/18031_2.png) [@DuckenScott](https://discuss.dev.twitch.com/u/DuckenScott)\
**Post date:** [January 17, 2023, 9:41am UTC](https://discuss.dev.twitch.com/t/invalid-authorization-code-axios-post-request/42864/3 "2023-01-17T09:41:07Z")

</div>

> [@BarryCarlyon](#):
>
> Addititionally your JS code indicates (`DomContentLoaded`) that you appear to be doing a `code` to `token` exchange in the front end, which will leak you private `client_secret` to the world.

Yes I have refresh a new code and it does work really well.

This code was for testing purposes but I will leave all my code in a secure file of course 🙂

Thank you for your answer ! 😃

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 17, 2023, 9:56am UTC](https://discuss.dev.twitch.com/t/invalid-authorization-code-axios-post-request/42864/4 "2023-01-17T09:56:01Z")

</div>

> [@DuckenScott](#):
>
> This code was for testing purposes but I will leave all my code in a secure file of course 🙂

If you are making the request from the front end and not the backend then users can extract the client secret from the axios call made as it will log in the network inspector part of any web browser inspector.

So a “secure file” doesn’t really exist on the front end.

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [February 16, 2023, 9:56am UTC](https://discuss.dev.twitch.com/t/invalid-authorization-code-axios-post-request/42864/5 "2023-02-16T09:56:56Z")

</div>

Closed on February 16, 2023, 9:56am UTC

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