Closed Zenahr closed 2 years ago
I might add that when initiating the auth flow the user is met with this screen:
I've also tried these options:
auth_twitch = make_twitch_blueprint(
client_id='xxx',
client_secret='xxx',
redirect_url='http://localhost:5000/redirect',
scope='user_read'
)
It still seems to redirect to http://localhost/redirect/
instead of http://localhost:5000/redirect/
as per the options defined above.
On Twitch, you need to set the "OAuth Redirect URL" to the value of Flask-Dance's authorized_url
, which is /twitch/authorized
by default. That will allow Flask-Dance to receive and save the OAuth token from Twitch, and then Flask-Dance will redirect the user to the redirect_url
that you define. See the Understanding the Magic doc page.
@singingwolfboy Thanks for your reply. The redirect leads to http://localhost/twitch/authorized
, I've added this array to the OAuth Redirect URLs on Twitch:
However, the problem still persists.
http://localhost/twitch/authorized?error=redirect_mismatch&error_description=Parameter+redirect_uri+does+not+match+registered+URI&state=REDACTED
I've tried out the same exact setup with GitHub, which worked, and Twitch, which, again, failed.
Here's the complete code:
from flask import Flask, redirect, url_for
from flask_dance.contrib.twitch import make_twitch_blueprint, twitch
import os
app = Flask(__name__)
app.secret_key = "xxx" # Replace this with your own secret!
blueprint = make_twitch_blueprint(
client_id="xxx",
client_secret="xxx",
)
app.register_blueprint(blueprint, url_prefix="/login")
@app.route("/")
def index():
if not twitch.authorized:
return redirect(url_for("twitch.login"))
resp = twitch.get("/user")
assert resp.ok
return "You are @{login} on twitch".format(login=resp.json()["login"])
if __name__ == "__main__":
app.run(debug=True, ssl_context='adhoc')
Redirect URL is set to https://127.0.0.1:5000/login/twitch/authorized
on Twitch.com (for GitHub I had used https://127.0.0.1:5000/login/github/authorized
with success)
The error is still https://127.0.0.1:5000/login/twitch/authorized/?error=redirect_mismatch&error_description=Parameter+redirect_uri+does+not+match+registered+URI&state=xxx
I cannot tell what the problem here is as I've used the same, exact setup successfully with GitHub as a provider but have it fail with Twitch @singingwolfboy
I solved this problem by waiting a couple minutes for Twitch to take effect over the new changes I made.
Using https://flask-dance.readthedocs.io/en/latest/providers.html#module-flask_dance.contrib.twitch
Current implementation:
Twitch configuration:
I believe the Twitch configuration to be correct, so this leaves me with flask-dance. Am I missing something?