Make Swagger Auth URLs https #107

This commit is contained in:
Daniel Grams 2021-02-12 09:03:34 +01:00
parent 78f1d99548
commit 1104bde5b4
2 changed files with 25 additions and 2 deletions

View File

@ -6,14 +6,23 @@ from project.services.event import upsert_event_category
from project.models import Location
from flask import url_for
from apispec.exceptions import DuplicateComponentNameError
import os
@app.before_first_request
def add_oauth2_scheme():
# At some sites the https scheme is not set yet
if os.getenv("AUTHLIB_INSECURE_TRANSPORT", "False").lower() in ["true", "1"]:
authorizationUrl = url_for("authorize", _external=True)
tokenUrl = url_for("issue_token", _external=True)
else:
authorizationUrl = url_for("authorize", _external=True, _scheme="https")
tokenUrl = url_for("issue_token", _external=True, _scheme="https")
oauth2_scheme = {
"type": "oauth2",
"authorizationUrl": url_for("authorize", _external=True),
"tokenUrl": url_for("issue_token", _external=True),
"authorizationUrl": authorizationUrl,
"tokenUrl": tokenUrl,
"flow": "accessCode",
"scopes": scopes,
}

14
tests/test_init_data.py Normal file
View File

@ -0,0 +1,14 @@
import pytest
@pytest.mark.parametrize("insecure", [None, "0", "1"])
def test_add_oauth2_scheme(app, utils, insecure):
import os
if insecure:
os.environ["AUTHLIB_INSECURE_TRANSPORT"] = insecure
else:
del os.environ["AUTHLIB_INSECURE_TRANSPORT"]
url = utils.get_url("home")
utils.get_ok(url)