OAuth authorization code flow token for Discord bot

To obtain a token to access Twitch prividged data.

  • You need to create a webpage.
  • That webpage will display a <a href="" that starts https://id.twitch.tv/oauth2/authorize
  • user clicks that link
  • user accepts of denies the link
  • if they accept they come back to your return URL with a ?code= you exchange that ?code= for an access token and refresh token via a HTTP POST request.
  • You store the user access token and refresh tokens
  • Use the user access token till it expires, then make a new token using the refresh token.
  • You may get a new refresh token when doing so.

If the refresh token doesn’t work then you’ll need the use you want to read subs for to do this flow all over again.

So,

If you left it as localhost then sounds like you are authing yourself, then you just need a webserver at that URL to do the auth process.

The above is for “regular” oAuth

You can instead use implict but then every 60 days you have to do the manual steps all over again. (Also generally thats what the third party third party token gens use which makes it annoying to seed it with a new token perodically.

Here are two example projects

One in node and one in PHP that demonstrate this flow. You would need to modify it to store the token/refresh token whever you need to for the discord bot to access it