diff --git a/helper.py b/helper.py index 87ac776..230bef9 100644 --- a/helper.py +++ b/helper.py @@ -7,12 +7,6 @@ from flask.logging import create_logger app = Flask(__name__) LOG = create_logger(app) -AUTH_TYPE = os.environ["AUTH_TYPE"].replace('"','').lower() - -if AUTH_TYPE == "oidc": - from flask_oidc import OpenIDConnect - oidc = OpenIDConnect(app) - def pretty_print_duration(duration): """ Prints a duration in human-readable formats """ @@ -267,9 +261,6 @@ def access_checks(): def load_checks(): """ Bundles all the checks into a single function to call easier """ - # If Auth Type is OIDC, check if a user is logged in: - if AUTH_TYPE == "oidc": - if not oidc.user_loggedin: return "login_page" # General error checks. See the function for more info: if access_checks() != "Pass": return 'error_page' # If the API key fails, redirect to the settings page: diff --git a/server.py b/server.py index 10d9be1..27d2689 100644 --- a/server.py +++ b/server.py @@ -76,14 +76,22 @@ if AUTH_TYPE == "oidc": from flask_oidc import OpenIDConnect oidc = OpenIDConnect(app) - # Check if OIDC user is logged in before routing to any page: - @app.route('/login') - @oidc.require_login - def login_page(): - LOG.error("Checking if the user is logged in...: "+str(oidc.user_loggedin)) - LOG.error("oidc.user_getfield('email'): "+oidc.user_getfield('email')) - if not oidc.user_loggedin: - LOG.error("User is not logged in. Redirecting to login") + # Decorate all functions with @oidc.require_login: + # Get a list of all public pages: + + def has_no_empty_params(rule): + defaults = rule.defaults if rule.defaults is not None else () + arguments = rule.arguments if rule.arguments is not None else () + return len(defaults) >= len(arguments) + + links = [] + for rule in app.url_map.iter_rules(): + # Filter out rules we can't navigate to in a browser + # and rules that require parameters + if has_no_empty_params(rule): + url = url_for(rule.endpoint, **(rule.defaults or {})) + links.append((url, rule.endpoint)) + # links is now a list of url, endpoint tuples elif AUTH_TYPE == "basic": # https://flask-basicauth.readthedocs.io/en/latest/ @@ -104,6 +112,10 @@ elif AUTH_TYPE == "basic": #def oidctest_page(): # return 'Welcome %s' % oidc.user_getfield('email') +@app.route("/site-map") +def site_map(): + return Markup(links) + @app.route('/') @app.route('/overview') def overview_page():