Why do I get a mismatching state error when I am making a web app that includes logging in with Twitch using Flask-Dance?

27 Views Asked by At

When I click my link to login with Twitch, I get this page:

enter image description here

Then I click continue, and I get an error message: oauthlib.oauth2.rfc6749.errors.MismatchingStateError: (mismatching_state) CSRF Warning! State not equal in request and response.

Here is my routes.py code:

from roulette_app import app
from flask import render_template, redirect, url_for, session
from flask_dance.contrib.twitch import make_twitch_blueprint, twitch

twitch_blueprint = make_twitch_blueprint(client_id="<MYID>", client_secret="<MYSECRET>", redirect_url="https://localhost:443/login/twitch/authorized")
app.register_blueprint(twitch_blueprint, url_prefix="/login")

@app.route('/')
def home():
    return render_template('home.html')

@app.route('/about')
def about():
    readme_content = read_readme()
    return render_template('about.html', readme_content=readme_content)

def read_readme():
    with open('README.md','r') as file:
        readme_content = file.read()
        return readme_content

@app.route('/pastpolls')
def pastpolls():
    return render_template('pastpolls.html')

@app.route('/login/twitch/authorized')
def twitch_authorized():
    if not twitch.authorized:
        return redirect(url_for("twitch.login"))
    resp = twitch.get("/user")
    if resp.ok:
        user_info = resp.json()
        session['user_id'] = user_info['id']
        session['user_name'] = user_info['display_name']
    return redirect(url_for("home")) 

I have made my app https already, I have double checked my redirect urls on Twitch

0

There are 0 best solutions below