401 error when invalid grant error is raised

This commit is contained in:
Jeremy Zhang 2019-11-20 19:49:34 -08:00
parent d51410d802
commit c45c98dfb9
2 changed files with 7 additions and 3 deletions

View File

@ -5,6 +5,7 @@ from flask import session, abort, url_for, request
from titanembeds.utils import redis_store, make_user_cache_key
from flask_socketio import disconnect
import time
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
authorize_url = "https://discordapp.com/api/oauth2/authorize"
token_url = "https://discordapp.com/api/oauth2/token"
@ -32,7 +33,10 @@ def make_authenticated_session(token=None, state=None, scope=None):
def discordrest_from_user(endpoint):
token = session['user_keys']
discord = make_authenticated_session(token=token)
try:
req = discord.get("https://discordapp.com/api/v6{}".format(endpoint))
except InvalidGrantError as ex:
abort(401)
return req
def get_current_authenticated_user():

View File

@ -1845,10 +1845,10 @@
});
fet.fail(function(data) {
if (data.status == 403) {
$('#loginmodal').modal('open');
setTimeout(function () {$('#loginmodal').modal('open');}, 2000);
Materialize.toast('Authentication error! You have been disconnected by the server.', 10000);
} else if (data.status == 401) {
$('#loginmodal').modal('open');
setTimeout(function () {$('#loginmodal').modal('open');}, 2000);
Materialize.toast('Session expired! You have been logged out.', 10000);
}
setVisitorMode(true);