From 0431cf7fc11e7ea70d67bb516eafb1a839999b80 Mon Sep 17 00:00:00 2001 From: Yogesh Mahajan Date: Wed, 10 May 2023 14:39:35 +0530 Subject: [PATCH] Ensure the user is able to log in if the specified OAUTH2_USERNAME_CLAIM is present in the OAuth2 profile. #6267 --- web/pgadmin/authenticate/oauth2.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/web/pgadmin/authenticate/oauth2.py b/web/pgadmin/authenticate/oauth2.py index 8922e9923..cf083828a 100644 --- a/web/pgadmin/authenticate/oauth2.py +++ b/web/pgadmin/authenticate/oauth2.py @@ -137,19 +137,18 @@ class OAuth2Authentication(BaseAuthentication): username = profile[username_claim] else: error_msg = "The claim '%s' is required to login into " \ - "pgAdmin. Please update your Oauth2 profile." % ( + "pgAdmin. Please update your OAuth2 profile." % ( username_claim) current_app.logger.exception(error_msg) return False, gettext(error_msg) - - if not email or email == '': - current_app.logger.exception( - "An email id is required to login into pgAdmin. " - "Please update your Oauth2 profile." - ) - return False, gettext( - "An email id is required to login into pgAdmin. " - "Please update your Oauth2 profile.") + else: + if not email or email == '': + error_msg = "An email id or OAUTH2_USERNAME_CLAIM is" \ + " required to login into pgAdmin. Please update your" \ + " OAuth2 profile for email id or set" \ + " OAUTH2_USERNAME_CLAIM config parameter." + current_app.logger.exception(error_msg) + return False, gettext(error_msg) user, msg = self.__auto_create_user(username, email) if user: