C# API Login with Twitch (getting back the token)

Hello,

I’m doing a chatbot.
For now : Users can log filling manually their Channel Name and OAuth Token.

In Progress : I’m trying to do a Log In with Twitch Button.
I managed to send the user on the Twitch authentication page :slight_smile:
string url = String.Format("https://id.twitch.tv/oauth2/authorize?response_type=token&client_id={0}&redirect_uri={1}&scope=chat:read&force_verify=true&state=123456", Properties.Settings.Default.ClientID, "https://twitchapps.com/tokengen/"); Process.Start(url);

This send me to the twitch authentication page and then show me a page with a token (Twitch OAuth Token Generator)
(123456abcdefghijABCDEFGHIJ not being my real access token but you got it :slight_smile: )

I would like to know :
Can I get back to my application the user channel name and his token automatically so he doesn’t have to copy and paste it manually ?
(and how ? ^^)

Thanks !

Shakawah

You are using implicit auth, you’ll get better mileage with the “authorization code flow”

As otherwise you need some javascript code to capture the URL fragment and submit that to the server.

With your current solution to extract the token you need to do something like this

But that only presents it to the Webpage, which then has to submit if off. And this token cannot be refreshed as you don’t have the refresh token

Thanks for your answer.

I’m a beginner so I don’t get everything.

First, I tried getting the “Authorization code flow” instead of “impicit auth” (if I got this right, this means changing “response_type=token” to “response_type=code” ?)
But now when i Log in I have this :
oauth

There is still some stuff I don’t understand sorry :confused:

So you are attempting to use a third party generator instead of building your own flow?

Thats the problem, you are partially implement oAuth and using someone elses tool to do the work.

You need to build your own webpage that implements oAuth to collect and store/use the token(s)

Oh ok I think i know what you mean.

I was using the default Twitch redirect Uri.

I don’t know a lot about web programming so I don’t even know where to start.
Should I still use the “https://id.twitch.tv/oauth2/authorize?.…” but change the redirect_uri ?
Cause at first I was trying to redirect to LocalHost but it wasn’t working.

I will try to figure this out. :grimacing:

The default is localhost, not twitchapps?!

You need a webserver at localhost to capture the event.

A nodeJS/javascript example of a user oAuth flow is at

I finally found a solution using “HttpWebRequest” on the localhost ! :slight_smile:

Thanks for the help.

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