Skip to content

Commit

Permalink
feat: [pgadminoauth2] add support for oauth2 profile arrays, empty er…
Browse files Browse the repository at this point in the history
…ror log
  • Loading branch information
hauserkristof committed Jan 22, 2025
1 parent 5ee0328 commit c60d3b4
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions web/pgadmin/authenticate/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,38 @@ def get_friendly_name(self):
def validate(self, form):
return True, None

def get_profile_dict(self, profile):
"""
Returns the dictionary from profile whether it's a list or dictionary.
Includes additional type checking.
"""
if isinstance(profile, list):
return profile[0] if profile else {}
elif isinstance(profile, dict):
return profile
else:
return {}

def login(self, form):
profile = self.get_user_profile()
profile_dict = self.get_profile_dict(profile)

current_app.logger.debug(f"profile: {profile}")
current_app.logger.debug(f"profile_dict: {profile_dict}")

if not profile_dict:
error_msg = "No profile data found."
current_app.logger.exception(error_msg)
return False, gettext(error_msg)

email_key = \
[value for value in self.email_keys if value in profile.keys()]
email = profile[email_key[0]] if (len(email_key) > 0) else None
[value for value in self.email_keys if value in profile_dict.keys()]
email = profile_dict[email_key[0]] if (len(email_key) > 0) else None

if not email:
error_msg = "No email found in profile data."
current_app.logger.exception(error_msg)
return False, gettext(error_msg)

username = email
username_claim = None
Expand Down

0 comments on commit c60d3b4

Please sign in to comment.