I am currently writing a discord dashboard for my discord bot and using flask oauth library to deal with the oauth from discord.
This is the code that is handling the oauth.
@app.route('/login')
def login():
return discord_oauth.authorize(callback=url_for('authorized', _external=True))
@app.route('/logout')
def logout():
session.pop('discord_token', None)
return redirect(url_for('index'))
@app.route('/authorized')
def authorized():
resp = discord_oauth.authorized_response()
print("resp data" + resp.data)
print("resp status" + resp.status)
print("resp content" + resp.content)
if resp is None or isinstance(resp, Exception):
return 'Access denied: reason=' + request.args['error'] + '&error_description=' + request.args['error_description']
session['discord_token'] = (resp['access_token'], '')
return redirect(url_for('select_guild'))
When i click authorize and head to the redirect uri specified in the code and in the discord oauth page this error appears.
* Restarting with stat
* Debugger is active!
* Debugger PIN: 548-765-053
127.0.0.1 - - [03/Jun/2023 20:57:32] "GET /authorized?code=MMwkjYncCyrM9BDIozg0CcLCcNFfya HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\Users\bob\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask\app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\bob\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask\app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\bob\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask\app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\bob\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask\app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\bob\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask\app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\bob\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask\app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\bob\Documents\JellyFishBot\main.py", line 46, in authorized
resp = discord_oauth.authorized_response()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\bob\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask_oauthlib\client.py", line 708, in authorized_response
data = self.handle_oauth2_response(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\bob\AppData\Local\Programs\Python\Python311\Lib\site-packages\flask_oauthlib\client.py", line 691, in handle_oauth2_response
raise OAuthException(
flask_oauthlib.client.OAuthException: Invalid response from discord
127.0.0.1 - - [03/Jun/2023 20:57:33] "GET /authorized?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 304 -
127.0.0.1 - - [03/Jun/2023 20:57:33] "GET /authorized?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 304 -
127.0.0.1 - - [03/Jun/2023 20:57:33] "GET /authorized?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 304 -
As you can see with the print statements in authorized I have tried to rule out the issue but when trying to print them out they don't print.