diff --git a/src/api/oauth_providers/github.py b/src/api/oauth_providers/github.py index 6312c9c..4d7dd47 100644 --- a/src/api/oauth_providers/github.py +++ b/src/api/oauth_providers/github.py @@ -13,7 +13,12 @@ from crud.sessions import create_login_session from api.model import LoginResponse -github_cnf = json.load(open("/src/app/config/github_client_secret.env.json")) +try: + github_cnf = json.load(open("/src/app/config/github_client_secret.env.json")) +except FileNotFoundError: + raise FileNotFoundError( + "GitHub OAuth Config File not found (github_client_secret.env.json). Please disable this OAuth Provider, or create the file as described in the Docs." + ) REDIRECT_URI = SignupConfig.oauth_base_url + "/oauth/github/callback" CLIENT_ID = github_cnf["client_id"] CLIENT_SECRET = github_cnf["client_secret"] diff --git a/src/api/oauth_providers/google.py b/src/api/oauth_providers/google.py index c9bd60f..44524c2 100644 --- a/src/api/oauth_providers/google.py +++ b/src/api/oauth_providers/google.py @@ -23,15 +23,20 @@ ) # Initialize Googles OAuth Flow -flow = Flow.from_client_secrets_file( - client_secrets_file="/src/app/config/google_client_secret.env.json", - scopes=[ - "https://www.googleapis.com/auth/userinfo.email", - "openid", - "https://www.googleapis.com/auth/userinfo.profile", - ], - redirect_uri=SignupConfig.oauth_base_url + "/oauth/google/callback", -) +try: + flow = Flow.from_client_secrets_file( + client_secrets_file="/src/app/config/google_client_secret.env.json", + scopes=[ + "https://www.googleapis.com/auth/userinfo.email", + "openid", + "https://www.googleapis.com/auth/userinfo.profile", + ], + redirect_uri=SignupConfig.oauth_base_url + "/oauth/google/callback", + ) +except FileNotFoundError: + raise FileNotFoundError( + "Google OAuth Config File not found (google_client_secret.env.json). Please disable this OAuth Provider, or create the file as described in the Docs." + ) @router.get("/login") diff --git a/src/tools/conf/SignupConfig.py b/src/tools/conf/SignupConfig.py index 473b2df..b8c8ab4 100644 --- a/src/tools/conf/SignupConfig.py +++ b/src/tools/conf/SignupConfig.py @@ -9,26 +9,47 @@ class SignupConfig: oauth_providers: list[str] = config["signup"]["oauth"]["providers_enabled"] oauth_base_url: str = str(config["signup"]["oauth"]["base_url"]).removesuffix("/") - def validate(self) -> bool: - """This is to Type Check the Configuration - - Raises: - ValueError: _description_ - ValueError: _description_ - - Returns: - bool: _description_ - """ - if isinstance(self.enable_conf_email, bool): + def validate_types(self) -> bool: + """This is to Type Check the Configuration""" + if not isinstance(self.enable_conf_email, bool): raise ValueError( "signup.enable_conf_email must be a boolean (got type {})".format( type(self.enable_conf_email) ) ) - if isinstance(self.conf_code_expiry, int): + if not isinstance(self.conf_code_expiry, int): raise ValueError( "signup.conf_code_expiry must be an integer (got type {})".format( type(self.conf_code_expiry) ) ) + if not isinstance(self.conf_code_complexity, int): + raise ValueError( + "signup.conf_code_complexity must be an integer (got type {})".format( + type(self.conf_code_complexity) + ) + ) + if not isinstance(self.enable_welcome_email, bool): + raise ValueError( + "signup.enable_welcome_email must be a boolean (got type {})".format( + type(self.enable_welcome_email) + ) + ) + if not isinstance(self.oauth_providers, list): + raise ValueError( + "signup.oauth.providers_enabled must be a list (got type {})".format( + type(self.oauth_providers) + ) + ) + if not all(isinstance(i, str) for i in self.oauth_providers): + raise ValueError("signup.oauth.providers_enabled must be a list of strings") + if not isinstance(self.oauth_base_url, str): + raise ValueError( + "signup.oauth.base_url must be a string (got type {})".format( + type(self.oauth_base_url) + ) + ) pass + + +SignupConfig().validate_types()