use preferred_username and fallback to name

This commit is contained in:
j 2024-11-09 17:02:57 +00:00
parent 5c6c7e37c7
commit 3bc2b1bd3e

View file

@ -12,7 +12,11 @@ User = get_user_model()
class OIDCAuthenticationBackend(mozilla_django_oidc.auth.OIDCAuthenticationBackend):
def create_user(self, claims):
user = super(OIDCAuthenticationBackend, self).create_user(claims)
username = claims.get("preferred_username")
username = None
for key in ('preferred_username', 'name'):
if claims.get(key):
username = claims[key]
break
n = 1
if username and username != user.username:
uname = username