From d34d07a9651cf4f09c922d78519280718d45b79e Mon Sep 17 00:00:00 2001 From: Mike Wallick Date: Mon, 7 Feb 2022 10:10:25 -0600 Subject: [PATCH 1/7] Allows for full URL OR local application page as a post login redirect URL --- app.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 398eee5a..b20abea7 100644 --- a/app.py +++ b/app.py @@ -2,6 +2,7 @@ import json import logging import logging.config +import re from flask import Flask, send_from_directory, render_template from flask import request, session, make_response, redirect @@ -222,14 +223,16 @@ def get_post_login_landing_page_url(): app_landing_page_url = "" # Pull from Config - hosturl = request.host_url.replace("http://", "{0}://".format(session[SESSION_INSTANCE_SETTINGS_KEY]["app_scheme"])) + app_scheme = session[SESSION_INSTANCE_SETTINGS_KEY]["app_scheme"] + landingurl = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"] - if session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"]: - app_landing_page_url = hosturl + "{app_template}/{landing_page}".format( - app_template=session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_template"], - landing_page=session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"],) + # if the configured value is a full URL, then use it, don't try to build one + if re.match(r"^http[s]?://", landingurl): + app_landing_page_url = landingurl else: - app_landing_page_url = hosturl + "profile" + hosturl = request.host_url.replace("http://", "{0}://".format(app_scheme)) + landing_page = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"] + app_landing_page_url = "{0}{1}".format(hosturl, landing_page) # Check for from_uri key, this always overrides the config if FROM_URI_KEY in session: @@ -238,7 +241,6 @@ def get_post_login_landing_page_url(): session[FROM_URI_KEY] = "" logger.debug("app landing page {0}".format(app_landing_page_url)) - return app_landing_page_url From 3326ead388c6e994e231fee7003aa78a1094c29d Mon Sep 17 00:00:00 2001 From: Mike Wallick Date: Mon, 7 Feb 2022 12:20:07 -0600 Subject: [PATCH 2/7] Removes unnecessary string replacement code --- app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app.py b/app.py index b20abea7..b77bc570 100644 --- a/app.py +++ b/app.py @@ -230,9 +230,8 @@ def get_post_login_landing_page_url(): if re.match(r"^http[s]?://", landingurl): app_landing_page_url = landingurl else: - hosturl = request.host_url.replace("http://", "{0}://".format(app_scheme)) landing_page = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"] - app_landing_page_url = "{0}{1}".format(hosturl, landing_page) + app_landing_page_url = "{0}{1}".format(request.host_url, landing_page) # Check for from_uri key, this always overrides the config if FROM_URI_KEY in session: From 221712eba585b1cb8efdc0b3d895851d57cac563 Mon Sep 17 00:00:00 2001 From: Mike Wallick Date: Mon, 7 Feb 2022 12:22:09 -0600 Subject: [PATCH 3/7] Removes variable assignment that is never used --- app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app.py b/app.py index b77bc570..ba259024 100644 --- a/app.py +++ b/app.py @@ -223,7 +223,6 @@ def get_post_login_landing_page_url(): app_landing_page_url = "" # Pull from Config - app_scheme = session[SESSION_INSTANCE_SETTINGS_KEY]["app_scheme"] landingurl = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"] # if the configured value is a full URL, then use it, don't try to build one From a667bd039144147570f3daad9791b8121bd4ff15 Mon Sep 17 00:00:00 2001 From: Mike Wallick Date: Mon, 7 Feb 2022 10:10:25 -0600 Subject: [PATCH 4/7] Allows for full URL OR local application page as a post login redirect URL --- app.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 398eee5a..b20abea7 100644 --- a/app.py +++ b/app.py @@ -2,6 +2,7 @@ import json import logging import logging.config +import re from flask import Flask, send_from_directory, render_template from flask import request, session, make_response, redirect @@ -222,14 +223,16 @@ def get_post_login_landing_page_url(): app_landing_page_url = "" # Pull from Config - hosturl = request.host_url.replace("http://", "{0}://".format(session[SESSION_INSTANCE_SETTINGS_KEY]["app_scheme"])) + app_scheme = session[SESSION_INSTANCE_SETTINGS_KEY]["app_scheme"] + landingurl = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"] - if session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"]: - app_landing_page_url = hosturl + "{app_template}/{landing_page}".format( - app_template=session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_template"], - landing_page=session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"],) + # if the configured value is a full URL, then use it, don't try to build one + if re.match(r"^http[s]?://", landingurl): + app_landing_page_url = landingurl else: - app_landing_page_url = hosturl + "profile" + hosturl = request.host_url.replace("http://", "{0}://".format(app_scheme)) + landing_page = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"] + app_landing_page_url = "{0}{1}".format(hosturl, landing_page) # Check for from_uri key, this always overrides the config if FROM_URI_KEY in session: @@ -238,7 +241,6 @@ def get_post_login_landing_page_url(): session[FROM_URI_KEY] = "" logger.debug("app landing page {0}".format(app_landing_page_url)) - return app_landing_page_url From c5c8904f3b31073f0b105e3455970b8269a098bf Mon Sep 17 00:00:00 2001 From: Mike Wallick Date: Mon, 7 Feb 2022 12:20:07 -0600 Subject: [PATCH 5/7] Removes unnecessary string replacement code --- app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app.py b/app.py index b20abea7..b77bc570 100644 --- a/app.py +++ b/app.py @@ -230,9 +230,8 @@ def get_post_login_landing_page_url(): if re.match(r"^http[s]?://", landingurl): app_landing_page_url = landingurl else: - hosturl = request.host_url.replace("http://", "{0}://".format(app_scheme)) landing_page = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"] - app_landing_page_url = "{0}{1}".format(hosturl, landing_page) + app_landing_page_url = "{0}{1}".format(request.host_url, landing_page) # Check for from_uri key, this always overrides the config if FROM_URI_KEY in session: From 184f27f55e29fa26a5cae9022eacc9fd0c1fc5ff Mon Sep 17 00:00:00 2001 From: Mike Wallick Date: Mon, 7 Feb 2022 12:22:09 -0600 Subject: [PATCH 6/7] Removes variable assignment that is never used --- app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app.py b/app.py index b77bc570..ba259024 100644 --- a/app.py +++ b/app.py @@ -223,7 +223,6 @@ def get_post_login_landing_page_url(): app_landing_page_url = "" # Pull from Config - app_scheme = session[SESSION_INSTANCE_SETTINGS_KEY]["app_scheme"] landingurl = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"] # if the configured value is a full URL, then use it, don't try to build one From 0c3fdbfe1a44801422c6a3423a630b6f63869c20 Mon Sep 17 00:00:00 2001 From: Mike Wallick Date: Tue, 22 Mar 2022 16:57:21 -0500 Subject: [PATCH 7/7] Adds post login override URL environment variable --- .env.sample | 6 ++++++ app.py | 12 +++++------- config/app_config.py | 1 + docs/README.md | 2 ++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.env.sample b/.env.sample index 05e1af45..b17075fd 100644 --- a/.env.sample +++ b/.env.sample @@ -15,6 +15,12 @@ SITE_APP_CONFIG="./well-known/default-settings" APP_TEMPLATE="sample" APP_LOGINMETHOD="standard-widget" APP_NAME="Sample App" +# set this variable to a local page of the app +# e.g. profile, index +APP_POST_LOGIN_LANDING_URL="" +# set this variable to redirect to an absolute URL after login +# e.g. https://someother.web.app/ +APP_POST_LOGIN_OVERRIDE_LANDING_URL="" APP_SLOGAN="" APP_SUBSLOGAN="" APP_LOGO="" diff --git a/app.py b/app.py index 5162269c..ec18c47b 100644 --- a/app.py +++ b/app.py @@ -220,16 +220,14 @@ def oidc_callback_handler(): def get_post_login_landing_page_url(): logger.debug("get_post_login_landing_page_url()") - app_landing_page_url = "" - - # Pull from Config - landingurl = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"] + session_settings = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"] + app_landing_page_override_url = session_settings["app_post_login_override_landing_url"] # if the configured value is a full URL, then use it, don't try to build one - if re.match(r"^http[s]?://", landingurl): - app_landing_page_url = landingurl + if re.match(r"^http[s]?://", app_landing_page_override_url): + app_landing_page_url = app_landing_page_override_url else: - landing_page = session[SESSION_INSTANCE_SETTINGS_KEY]["settings"]["app_post_login_landing_url"] + landing_page = session_settings["app_post_login_landing_url"] app_landing_page_url = "{0}{1}".format(request.host_url, landing_page) # Check for from_uri key, this always overrides the config diff --git a/config/app_config.py b/config/app_config.py index c93231e8..760135a8 100644 --- a/config/app_config.py +++ b/config/app_config.py @@ -21,6 +21,7 @@ def get_app_version(): "settings": { "app_template": os.getenv("APP_TEMPLATE", "sample"), "app_post_login_landing_url": os.getenv("APP_POST_LOGIN_LANDING_URL", "profile"), + "app_post_login_override_landing_url": os.getenv("APP_POST_LOGIN_OVERRIDE_LANDING_URL", ""), "app_loginmethod": os.getenv("APP_LOGINMETHOD", "standard-widget"), "app_name": os.getenv("APP_NAME", "Sample App"), "app_slogan": os.getenv("APP_SLOGAN", ""), diff --git a/docs/README.md b/docs/README.md index 90b5ad51..2dce9b30 100644 --- a/docs/README.md +++ b/docs/README.md @@ -281,6 +281,8 @@ The `.env` file provides additional configuration depending on the functionality | APP_TEMPLATE | Enter the specific value based on the [vertical](#vertical-specific-variables) | | | APP_LOGINMETHOD | The login UX, widget, custom or redirect | Options: `standard-widget`, `passwordless-widget`,`custom-widget` | APP_NAME | some app name prominently displayed | | + | APP_POST_LOGIN_LANDING_URL | local page to redirect to after login | profile | + | APP_POST_LOGIN_OVERRIDE_LANDING_URL | absolute URL to redirect to after login | https://okta.com | | APP_SLOGAN | some slogan | | | APP_SUBSLOGAN | some subtitle | | | APP_LOGO | url to some logo | |