-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenConceptLab/ocl_issues#1338 | oidc overriden backend | to create a…
…nd find user
- Loading branch information
1 parent
91cbc63
commit f32186c
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |