diff --git a/auth-api/src/auth_api/utils/util.py b/auth-api/src/auth_api/utils/util.py index 55ab98f27..dac32e234 100644 --- a/auth-api/src/auth_api/utils/util.py +++ b/auth-api/src/auth_api/utils/util.py @@ -74,11 +74,15 @@ def mask_email(email: str) -> str: def get_request_environment(): """Return the environment corresponding to the user request.""" - env = None - sandbox_host = current_app.config["AUTH_WEB_SANDBOX_HOST"] - if os.getenv("FLASK_ENV") == "production" and sandbox_host in request.host_url: - env = "sandbox" - return env + env_override = request.headers.get('Environment-Override') + sandbox_host = current_app.config.get("AUTH_WEB_SANDBOX_HOST") + is_production = os.getenv("FLASK_ENV") == "production" + + if env_override: + return env_override + if is_production and sandbox_host in request.host_url: + return "sandbox" + return None def extract_numbers(input_string: str):