Include more informed error during callback

This commit is contained in:
Jeremy "EndenDragon" Zhang 2021-07-18 19:07:27 -07:00 committed by GitHub
parent a75f0a276b
commit 9de25eb0d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,15 +30,17 @@ def login_authenticated():
@user.route('/callback', methods=["GET"]) @user.route('/callback', methods=["GET"])
def callback(): def callback():
state = session.get('oauth2_state') state = session.get('oauth2_state')
if not state or request.values.get('error'): if not state:
return redirect(url_for('user.logout')) return redirect(url_for('user.logout', error="state_error"))
if request.values.get('error'):
return redirect(url_for('user.logout', error="discord_error {}".format(request.values.get('error'))))
discord = make_authenticated_session(state=state) discord = make_authenticated_session(state=state)
discord_token = discord.fetch_token( discord_token = discord.fetch_token(
token_url, token_url,
client_secret=config['client-secret'], client_secret=config['client-secret'],
authorization_response=request.url) authorization_response=request.url)
if not discord_token: if not discord_token:
return redirect(url_for('user.logout')) return redirect(url_for('user.logout', error="discord_user_token_fetch_error"))
session['user_keys'] = discord_token session['user_keys'] = discord_token
session['unauthenticated'] = False session['unauthenticated'] = False
session.permanent = True session.permanent = True
@ -628,4 +630,4 @@ def patreon_sync_post():
@user.route("/patreon/thanks") @user.route("/patreon/thanks")
@discord_users_only() @discord_users_only()
def patreon_thanks(): def patreon_thanks():
return render_template("patreon.html.j2", state="thanks") return render_template("patreon.html.j2", state="thanks")