Automated UserToken Generation

I have been trying to slowly work on my own twitch chat bot, I have gotten quite a bit handled, I can even set up the system to listen to voice commands, but one thing I can not sort out for the life of me is how to automate the user token generation when I start my bot.
https://id.twitch.tv/oauth2/authorize?response_type=code&client_id=” Currently I manually have to go to this webpage, sign-in(it automatically does it from caching yay chrome), await the return page and copy the token. I have to do this every time the token fails, typically every time I restart the bot, or every four hours-ish, and I am looking for a way to have the bot itself get that token so I can just run the node bot.js command have my bot doing work for me. The question I pose is, Is there a method, and how do I use it if so, to get your own user token directly in bot.js file without any human interaction with a web page?

Follow up question, If there is not any method to do so currently, is there a reason as to why not?

That is how oAuth works.

however

This flow returns a user access token, and a refresh token.

as per Getting OAuth Access Tokens | Twitch Developers

{
  "access_token": "<user access token>",
  "refresh_token": "<refresh token>",
  "expires_in": <number of seconds until the token expires>,
  "scope": ["<your previously listed scope(s)>"],
  "token_type": "bearer"
}

When your bot starts, if the access token is invalid you can use the refresh token to get a new access token

Then if the refresh token is sitll good you do not need to use the webpage/sign in stuff.

As you then use the refresh token to get a new access token and away you go (this may then return a new refresh token to store)

So in theory you only need to “seed” your bot with an access and refresh token ONCE and it will keep going until the refresh token is no longer usable.

Which shouldn’t happen, except as noted:

  • weird fun edge cases
  • you delinked yoru clientID from the bot user account
  • you reset the password on the bot user account

Security reasons!

And to Twitch, a bot isn’t a bot, it’s just a user account thats has chat messages run from a script. Just like a third party chat client.

Thank you so much, I had seen the refresh token thing at one point but did not fully understand it. Now that I have gotten logged in and performed actions I will start looking into how to properly use the refresh token. Thank you so much for your response.

Documents the usage of said refresh token

Thank you SO MUCH for giving me the information I needed to resolve my automation!

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