{ status: 400, message: 'Invalid authorization code' }

I’m building my project completly new from php to js.
I copied the same code but I always got { status: 400, message: ‘Invalid authorization code’ }

url: https://id.twitch.tv/oauth2/token?client_id=**(replaced)**&client_secret=**(replaced)**d&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Ftwitch&grant_type=authorization_code&code=n61ps7fvucwkfu708vpam6nb6xtozt

I dont know what the problem is

The code is already used is a common problem here. As the code is a one use code to be exchanged for a token

The code should be dynamically obtained from the URL as it’s a query strin parameter and not hard coded.

that was the response from oauth2/authorize

code: ‘n61ps7fvucwkfu708vpam6nb6xtozt’,
scope: ‘user:read:email’,
state: ‘qbf17d9ernqbf17d9ern’

I used the code from response

Then you have either

  • not used the code in time, they have about 5 minutes to live
  • you have already used the code to exchange for a token, they are one use

both options are not possible.

I try to get the access-token immediately

Then this suggests a fault in twitchClass.getTwitchAccessToken

Would need to see what that function is doing.

Broadly looks correct.

What does queryBuilder do?

Heres a simplier fetch example to reference


I tried it with your method and it worked.

THANKS! :+1:

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