From 11881746f441d816225a24831a5ff93d54408e06 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Sat, 27 Aug 2022 09:33:08 +0100 Subject: [PATCH] Allow passing SSO public key as parameter (for testing) --- ai_web_common/flask_sso/ext.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ai_web_common/flask_sso/ext.py b/ai_web_common/flask_sso/ext.py index 3e158f1..db3d16e 100644 --- a/ai_web_common/flask_sso/ext.py +++ b/ai_web_common/flask_sso/ext.py @@ -22,10 +22,15 @@ def init_sso(app, talisman): if 'SSO_DOMAIN' not in app.config: raise Exception('Must configure SSO_DOMAIN') - pubkey_file = app.config.get( - 'SSO_PUBLIC_KEY_FILE', '/etc/sso/public.key') - with open(pubkey_file, 'rb') as f: - pubkey = f.read() + # Allow passing the public key as a parameter (useful for testing) + # or read it from a file. + if 'SSO_PUBLIC_KEY' in app.config: + pubkey = app.config['SSO_PUBLIC_KEY'] + else: + pubkey_file = app.config.get( + 'SSO_PUBLIC_KEY_FILE', '/etc/sso/public.key') + with open(pubkey_file, 'rb') as f: + pubkey = f.read() # Ensure the login server URL is /-terminated. app.sso_login_server = app.config['SSO_LOGIN_SERVER'].rstrip('/') + '/' -- GitLab