From c0f14e326688877faf45318a49061db4de2eea8d Mon Sep 17 00:00:00 2001 From: VKTB <45173816+VKTB@users.noreply.github.com> Date: Wed, 20 Dec 2023 10:12:37 +0000 Subject: [PATCH] Load private and public key content into constants #4 --- ldap_jwt_auth/core/constants.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ldap_jwt_auth/core/constants.py diff --git a/ldap_jwt_auth/core/constants.py b/ldap_jwt_auth/core/constants.py new file mode 100644 index 0000000..93ccd98 --- /dev/null +++ b/ldap_jwt_auth/core/constants.py @@ -0,0 +1,20 @@ +""" +Module for the constants of the application. +""" +import sys + +from ldap_jwt_auth.core.config import config + +# Read the contents of the private and public key files into constants. These are used for encoding and decoding of JWT +# access and refresh tokens. +try: + with open(config.authentication.private_key_path, "r") as f: + PRIVATE_KEY = f.read() +except FileNotFoundError as exc: + sys.exit(f"Cannot find private key: {exc}") + +try: + with open(config.authentication.public_key_path, "r") as f: + PUBLIC_KEY = f.read() +except FileNotFoundError as exc: + sys.exit(f"Cannot find public key: {exc}")