Skip to content

Commit

Permalink
Merge pull request #332 from knikolla/fix/mokey_groups_list
Browse files Browse the repository at this point in the history
[mokey_oidc plugin] Handle groups claim as list
  • Loading branch information
aebruno authored Nov 5, 2021
2 parents 580a7df + 06ad22a commit f282f4e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions coldfront/plugins/mokey_oidc/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ def _sync_groups(self, user, groups):

user.userprofile.is_pi = is_pi

def _parse_groups_from_claims(self, claims):
groups = claims.get('groups', []) or []
if isinstance(groups, str):
groups = groups.split(';')

return groups

def create_user(self, claims):
email = claims.get('email')
username = claims.get('uid')
Expand All @@ -39,8 +46,8 @@ def create_user(self, claims):
user.first_name = claims.get('first', '')
user.last_name = claims.get('last', '')

groups = claims.get('groups', '')
self._sync_groups(user, groups.split(';'))
groups = self._parse_groups_from_claims(claims)
self._sync_groups(user, groups)

user.save()

Expand All @@ -55,8 +62,8 @@ def update_user(self, user, claims):
else:
logger.warn("Failed to update email. Could not find email for user %s in mokey oidc id_token claims: %s", username, claims)

groups = claims.get('groups', '')
self._sync_groups(user, groups.split(';'))
groups = self._parse_groups_from_claims(claims)
self._sync_groups(user, groups)

user.save()

Expand All @@ -78,17 +85,16 @@ def verify_claims(self, claims):
if len(ALLOWED_GROUPS) == 0 and len(DENY_GROUPS) == 0:
return verified and True

groups = claims.get('groups', '')
group_list = groups.split(';')
groups = self._parse_groups_from_claims(claims)

if len(ALLOWED_GROUPS) > 0:
for g in ALLOWED_GROUPS:
if g not in group_list:
if g not in groups:
return False

if len(DENY_GROUPS) > 0:
for g in DENY_GROUPS:
if g in group_list:
if g in groups:
return False

return verified and True

0 comments on commit f282f4e

Please sign in to comment.