Confusion on the authorization process

I am creating a chatbot, and I have a web portal to along with it. I can successfully authorize the chat bot application to my channel, get an access token, get an oauth token, connect to the chat and send chat messages. All seems good…except the problem is I can only send messages as myself and NOT as the bot account. How am I supposed to get the oauth token for the bot account when a user enables the chatbot application for their channel?

I call the twitch oath2/token with the chatbots client ID and secret. It’s my understanding that this returns a token for MY twitch account, but obviously I don’t need MY token, I need the token for the chatbots account…

I’m sure I just have a misunderstanding here. My chatbot uses a web portal, where any streamer can authorize the chatbot application and enable the chatbot for their channel. This uses a specific account for the chat bot, so how I do I get that chat bots token to pass along in the socket_create method?

Additional Context:

It’s my understanding that the current flow of my web portal is authorizing my chatbot APPLICATION access to the requested scopes, but the oauth token that I recieve is for whatever account the streamer has. Since the token flow requires a logged in twitch account, I obviously can’t let other streamers use the chat bot account, so it has to be their own accounts.

I am confused as to how I can let my chatbots account have access into all the different channels that have authorized it. How and where would I go about getting that token for the chatbot account? I could access the web portal using an admin account in incognito mode and sign in to the chatbots account, then authorize the chatbot application for that account, but then how does the chatbot account ever get access to the individual streamers channels? Is it all based on what channels have authorized the chatbot application? So if channel A authorizes the application, my chatbot account B can automatically connect to channel A with all the scopes defined for the application?

Since I am still developing and testing, using the streamers own account for sending messages in chat is fine, but I need to change this to use the chatbots account in the near future.

Your bot program will send messages as the user in the token that you gave your program to run on.

It runs as your account because you gave the program your account’s token t osend as

No the owner of the ClientID is irrelevant.

It’s all about whom authenticates to the ClientID.

To get a Token for the chat bot the controller of the chat bot

  • Visits your site
  • Hits login with Twitch
  • Is sent to Twitch
  • Checks they are logged in to twitch on the oAuth dialog as the expected account in this case the chatbot.

You get a token for the chat bot the same way you get a token for any user account.

With an oAuth flow where the person doing the oAuth flow checks they are logged in as the right account.

You do an oAuth flow to generate an oAuth token for your chatbot and store that somewhere and use it as needed

Streamers that want to use your chatbot come to your site and login as them, so you can do any operation that needs a streamer token

Now you have

  • chatbot token
  • streamer a token
  • streamer b token
  • streamer c token

Your chatbot program will use the chatbot token to read/write chat.
And will use the streamers token to do any other operations such as say running commercials

For example my chatbot system - BarryCarlyonBot - provides a way for a streamer to bring their own bot account to my program.

So a given setup will have two tokens, one for the streamer and one for the bot account.
Usign that token pair I’ll login to chat using the bot token, and run commericals or update the channel title/category using the streamers token

The same way you get a token for a streamer.

That is what I would do yes

Depends if you are using IRC or EventSub. I can’t suggest an answer without knowing which you are using.

There are a number of what if’s based on what you are doing or intending to do.

Until recently a user (or chatbot given a chatbot is just another user) could join as many channels over IRC as it wanted.

Now there are limits and if using EventSub there is a proceedure to follow, the bot account being a mod on the destination channel(s) not with standing

This was the bit I was missing, but after sleeping on it I realized it myself. Thanks for the great write up to clear any confusion.

I had actually referenced your github project several months ago when I first started looking into this project, although it was just a quick test via python :slight_smile: