I’m working on a custom Twitch app and I’m currently struggling with implementing OAuth authentication for user login. I’ve followed the official documentation for setting up OAuth with the Twitch API, but I’m running into an issue where the access token seems to be expired almost immediately after I generate it.
Here’s a simplified version of what I’m doing:
I send the user to the OAuth URL to authenticate.
The user successfully authenticates and I get the access token in the callback.
I attempt to use the access token immediately, but it returns an error: 401 Unauthorized.
Has anyone else run into this or have suggestions on what I might be missing? Are there any specific steps or parameters I should be checking to make sure the token remains valid?
This sounds like you got an oAuth code back and then tried to use that code as a token instead of doing step 3 to exchange a code for an access and refresh token.
The normal code flow is:
Create a URL and send the User To Twitch
They come back wtih a ?code if they accepted the link
You exchange the (one use) ?code for an access and refresh token
You use the access token until it’s close to or has expired
Use the refresh token to get a new access (and maybe new refresh token)