Skip to content

Commit

Permalink
move default sso providers to util.sso, verify sso providers are actu…
Browse files Browse the repository at this point in the history
…ally configured
  • Loading branch information
Kunsi committed Dec 24, 2024
1 parent 947366d commit 7193a5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
3 changes: 1 addition & 2 deletions frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@
get_user_assets,
is_within_timeframe,
login_required,
DEFAULT_SSO_PROVIDER,
)
from util.redis import REDIS
from util.sso import SSO_CONFIG
from util.sso import DEFAULT_SSO_PROVIDER, SSO_CONFIG

app = Flask(
__name__,
Expand Down
8 changes: 1 addition & 7 deletions util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@
from flask import abort, current_app, g, jsonify, redirect, request, session, url_for

from conf import CONFIG
from util.sso import DEFAULT_ADMIN_SSO_PROVIDER, DEFAULT_SSO_PROVIDER

from .ib_hosted import ib

DEFAULT_SSO_PROVIDER = CONFIG.get(
"DEFAULT_SSO_PROVIDER", list(CONFIG["oauth2_providers"].keys())[0]
)
DEFAULT_ADMIN_SSO_PROVIDER = CONFIG.get(
"DEFAULT_ADMIN_SSO_PROVIDER", list(CONFIG["oauth2_providers"].keys())[0]
)


def error(msg):
return jsonify(error=msg), 400
Expand Down
19 changes: 16 additions & 3 deletions util/sso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@

for provider in CONFIG["oauth2_providers"]:
if provider not in SSO_CONFIG:
raise RuntimeError(
f"SSO provider {provider} found in config, but not configured."
)
raise RuntimeError(f"SSO provider {provider} found in config, but not known.")


DEFAULT_SSO_PROVIDER = CONFIG.get(
"DEFAULT_SSO_PROVIDER", list(CONFIG["oauth2_providers"].keys())[0]
)
DEFAULT_ADMIN_SSO_PROVIDER = CONFIG.get(
"DEFAULT_ADMIN_SSO_PROVIDER", list(CONFIG["oauth2_providers"].keys())[0]
)

assert (
DEFAULT_SSO_PROVIDER in CONFIG["oauth2_providers"]
), f"SSO provider {DEFAULT_SSO_PROVIDER} set as default, but not configured."
assert (
DEFAULT_ADMIN_SSO_PROVIDER in CONFIG["oauth2_providers"]
), f"SSO provider {DEFAULT_ADMIN_SSO_PROVIDER} set as default, but not configured."

0 comments on commit 7193a5a

Please sign in to comment.