Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1338 | oidc overriden backend | to create a…
Browse files Browse the repository at this point in the history
…nd find user
  • Loading branch information
snyaggarwal committed Aug 1, 2022
1 parent 91cbc63 commit f32186c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions core/common/backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from mozilla_django_oidc.auth import OIDCAuthenticationBackend


class OCLOIDCAuthenticationBackend(OIDCAuthenticationBackend):
def create_user(self, claims):
"""Return object for a newly created user account."""
# {
# 'sub': '<str:uuid>',
# 'email_verified': <boolean>,
# 'realm_access': {
# 'roles': ['offline_access', 'default-roles-ocl', 'uma_authorization']
# },
# 'name': 'Inactive User',
# 'preferred_username': 'inactive',
# 'given_name': 'Inactive',
# 'family_name': 'User',
# 'email': 'inactive@user.com'
# }
from core.users.models import UserProfile
return UserProfile.objects.create_user(
claims.get('preferred_username'),
email=claims.get('email'),
**dict(
first_name=claims.get('given_name'),
last_name=claims.get('family_name'),
verified=claims.get('email_verified')
)
)

def filter_users_by_claims(self, claims):
from core.users.models import UserProfile

username = claims.get('preferred_username')

if not username:
return UserProfile.objects.none()

return UserProfile.objects.filter(username=username)

0 comments on commit f32186c

Please sign in to comment.