Invalid URL and Missing Schema After Sign-In on Flask

I have a very basic web app I am trying to deploy on an AWS with nginx, gunicorn, and flask. I can get the page to redirect to auth0 to sign in and make the call back. After that, in my gunicorn log I see what boils down to requests.exceptions.MissingSchema: Invalid URL 'None': No scheme supplied. Perhaps you meant https://None?, but I cannot figure out where I have not defined a URL.

Any help appreciated!

Nginx.conf (excerpt):

server {
		listen 443 ssl;
		server_name DOMAIN.com www.DOMAIN.com;
		root /var/www/DOMAIN;
		location /{
				proxy_pass http://unix:/var/www/DOMAIN/gunicorn.sock;
				include /etc/nginx/proxy_params;
		}


		location @backend {
				proxy_pass http://unix:/var/www/DOMAIN/gunicorn.sock;
				include /etc/nginx/proxy_params;
		}

		#listen 443 ssl; # managed by Certbot
		ssl_certificate /etc/letsencrypt/live/DOMAIN.com/fullchain.pem; # managed by Certbot
		ssl_certificate_key /etc/letsencrypt/live/DOMAIN.com/privkey.pem; # managed by Certbot
		include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
		ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

		access_log /var/log/nginx/DOMAIN.log;
		error_log /var/log/nginx/DOMAIN-error.log;
}

app.py (start and callback route)

from flask import Flask, render_template, request, redirect, url_for, session
from authlib.integrations.flask_client import OAuth
import sqlite3

app = Flask(__name__)
app.secret_key = 'your_secret_key'  # Change this to a random, secure key

oauth = OAuth(app)
oauth.register(
    name='auth0',
    client_id='private',
    client_secret='',
    authorize_url='https://DOMAIN.us.auth0.com/authorize',
    authorize_params=None,
    authorize_prompt=None,
    authorize_response=None,
    token_url='https://DOMAIN.us.auth0.com/oauth/token',
    token_params=None,
    client_kwargs={'scope': 'openid profile email'},
    userinfo_endpoint='https://DOMAIN.us.auth0.com/userinfo',
    callback_uri='https://DOMAIN.com/callback',
)

###other

@app.route('/callback', methods=["GET", "POST"])
def callback():
    print("###############################")
    token = oauth.auth0.authorize_access_token()
    resp = oauth.auth0.get('userinfo')
    user_info = resp.json()
    session['profile'] = user_info
    return redirect(url_for('index'))

And the error log

ERROR in app: Exception on /callback [GET]
Traceback (most recent call last):
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/var/www/DOMAIN/app.py", line 64, in callback
    token = oauth.auth0.authorize_access_token()
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/authlib/integrations/flask_client/apps.py", line 101, in authorize_access_token
    token = self.fetch_access_token(**params, **kwargs)
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/authlib/integrations/base_client/sync_app.py", line 342, in fetch_access_token
    token = client.fetch_token(token_endpoint, **params)
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/authlib/oauth2/client.py", line 207, in fetch_token
    return self._fetch_token(
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/authlib/oauth2/client.py", line 351, in _fetch_token
    resp = self.session.post(
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/authlib/integrations/requests_client/oauth2_session.py", line 109, in request
    return super(OAuth2Session, self).request(
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/requests/sessions.py", line 575, in request
    prep = self.prepare_request(req)
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/requests/sessions.py", line 486, in prepare_request
    p.prepare(
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/requests/models.py", line 368, in prepare
    self.prepare_url(url, params)
  File "/var/www/DOMAIN/venv/lib/python3.10/site-packages/requests/models.py", line 439, in prepare_url
    raise MissingSchema(
requests.exceptions.MissingSchema: Invalid URL 'None': No scheme supplied. Perhaps you meant https://None?
1 Like