-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
22 additions
and
2 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,22 @@ | ||
from django.contrib.auth import get_user_model | ||
from simple_openid_connect.integrations.django.models import OpenidUser | ||
from simple_openid_connect.integrations.django.user_mapping import UserMapper | ||
|
||
|
||
class KarmaUserMapper(UserMapper): | ||
def handle_federated_userinfo(self, user_data): | ||
# if there is already a user with this username, we create the openid association if it does not exist yet | ||
User = get_user_model() | ||
try: | ||
user = User.objects.get(username=user_data.preferred_username) | ||
OpenidUser.objects.get_or_create( | ||
sub=user_data.sub, | ||
defaults={ | ||
"user": user, | ||
}, | ||
) | ||
except User.DoesNotExist: | ||
# if the user does not exist, it is automatically created by the super class | ||
pass | ||
return super().handle_federated_userinfo(user_data) | ||
|
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