mirror of
				https://github.com/TitanEmbeds/Titan.git
				synced 2025-11-04 07:47:10 +01:00 
			
		
		
		
	401 error when invalid grant error is raised
This commit is contained in:
		@@ -5,6 +5,7 @@ from flask import session, abort, url_for, request
 | 
				
			|||||||
from titanembeds.utils import redis_store, make_user_cache_key
 | 
					from titanembeds.utils import redis_store, make_user_cache_key
 | 
				
			||||||
from flask_socketio import disconnect
 | 
					from flask_socketio import disconnect
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
 | 
					from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
authorize_url = "https://discordapp.com/api/oauth2/authorize"
 | 
					authorize_url = "https://discordapp.com/api/oauth2/authorize"
 | 
				
			||||||
token_url = "https://discordapp.com/api/oauth2/token"
 | 
					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):
 | 
					def discordrest_from_user(endpoint):
 | 
				
			||||||
    token = session['user_keys']
 | 
					    token = session['user_keys']
 | 
				
			||||||
    discord = make_authenticated_session(token=token)
 | 
					    discord = make_authenticated_session(token=token)
 | 
				
			||||||
    req = discord.get("https://discordapp.com/api/v6{}".format(endpoint))
 | 
					    try:
 | 
				
			||||||
 | 
					        req = discord.get("https://discordapp.com/api/v6{}".format(endpoint))
 | 
				
			||||||
 | 
					    except InvalidGrantError as ex:
 | 
				
			||||||
 | 
					        abort(401)
 | 
				
			||||||
    return req
 | 
					    return req
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_current_authenticated_user():
 | 
					def get_current_authenticated_user():
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1845,10 +1845,10 @@
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
        fet.fail(function(data) {
 | 
					        fet.fail(function(data) {
 | 
				
			||||||
            if (data.status == 403) {
 | 
					            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);
 | 
					                Materialize.toast('Authentication error! You have been disconnected by the server.', 10000);
 | 
				
			||||||
            } else if (data.status == 401) {
 | 
					            } else if (data.status == 401) {
 | 
				
			||||||
                $('#loginmodal').modal('open');
 | 
					                setTimeout(function () {$('#loginmodal').modal('open');}, 2000);
 | 
				
			||||||
                Materialize.toast('Session expired! You have been logged out.', 10000);
 | 
					                Materialize.toast('Session expired! You have been logged out.', 10000);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            setVisitorMode(true);
 | 
					            setVisitorMode(true);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user