Twitch login redirect issue

Hello there! I’m using the twitch api v5 with python & flask to try to authenticate

This is the following code i’m using:

from flask import Flask, abort, request
app = Flask(name)

@app.route(’/’, methods =[‘GET’])
def homepage():
request2 = requests.get('https://api.twitch.tv/kraken/oauth2/authorize?’+
‘response_type=token’+
‘&client_id=5hi6d1chqez0e845sfgqrec0ls2e0n’+
‘&redirect_uri=http://localhost’+
‘&scope=viewing_activity_read’+
‘&state=0c72sjv7abz46vaouzw1a8w13k9q2j’)

return request2.text

@app.route(’/client_event/new’, methods=[‘POST’])
@app.route(’/sessions/new’, methods = [‘POST’])
def redirector():
return ‘test’

I added the last two routes because it was showing me a 404 before and now its allowing the twitch login to show the “sending…” button, but not really sure what to do now. Its not redirecting to allow the user to authenticate, just staying at the current login screen.

You are redirecting the user to Twitch at this step? Not getting and rendering the HTML?

Step 1 of oAuth is to actually send the user to Twitch?

I highly doubt you have access to VHS so this scope is likely useless for you!

request2 = requests.get(‘https://api.twitch.tv/kraken/oauth2/authorize?’+

that request2 = requests.get is actually doing the get and when returning the request2.text, it is displaying the twitch login html page from twitch.

i’m just following the instructions from the v5 docs and i’m just lost at this point. Can’t seem to get past part 1.

Looks like an error in the Docs

OAuth Authorization Code Flow (User Access Tokens)

Shouldn’t be

Use this request:

GET https://api.twitch.tv/kraken/oauth2/authorize
?client_id=<your client ID>
&redirect_uri=<your registered redirect URI>
&response_type=code
&scope=<space-separated list of scopes>

It should be:

"Redirect the user to this URL via GET"

Edit: was about to flag this to the devs… but I already did…

oh, so i have to redirect the user to this GET url instead for it to work?

Yes (as apposed to redirecting a user via post with a form or something)

Tried the way you described and this page isn’t doing anything at all

Capture

I don’t think that will work since you are just making a GET request and dumping the output to the user. (I could be wrong since I am not familiar with Flask)

Try issuing a HTTP redirect to the URL instead so the user can login and complete the authentication process. Once they complete it will redirect back to your app at your redirect_uri.

you mentioned redirecting to the URL.
What exactly are you referring to when you say URL? the get request URL? the ‘/’ route, or http://localhost
?

thank you George!!!
i did return return redirect(request2.url) and then the page worked and now i’m returned to the following:
http://localhost/?code=rgkzyaguo7iv76ywa7swzwjuu3v8ek&scope=viewing_activity_read+user_subscriptions

which this is exactly what is documented in the twitch v5 documentation. Now I need to figure out what to do next with that since currently its the lost page. But glad i’m over the hurdle of not getting any further on the login

Btw. there is a reason why it’s called “Client Secret”, you just leaked a lot of things other people could use to use your bot’s data. Maybe you should remove the picture completely or reupload it censored.

1 Like

thanks lol, forgot about that

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