Skip to content

Commit

Permalink
Make email comparison for SAML case insensitive
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Bernardi <[email protected]>
  • Loading branch information
fastlorenzo committed Dec 11, 2024
1 parent 2bad133 commit 154fe90
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/iam/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SocialAccountAdapter(DefaultSocialAccountAdapter):
def pre_social_login(self, request, sociallogin):
email_address = next(iter(sociallogin.account.extra_data.values()))[0]
try:
user = User.objects.get(email=email_address)
user = User.objects.get(email=email_address.lower())
sociallogin.user = user
sociallogin.connect(request, user)
except User.DoesNotExist:
Expand Down
3 changes: 3 additions & 0 deletions backend/iam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ def delete(self, *args, **kwargs):
logger.info("user deleted", user=self)

def save(self, *args, **kwargs):
# Make sure to always convert username to lowercase for easier comparison with SSO
if self.email:
self.email = self.email.lower()
super().save(*args, **kwargs)
logger.info("user saved", user=self)

Expand Down
2 changes: 1 addition & 1 deletion backend/iam/sso/saml/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def dispatch(self, request, organization_slug):
login.state["next"] = next_url
try:
email = auth._nameid
user = User.objects.get(email=email)
user = User.objects.get(email=email.lower())
idp_first_name = auth._attributes.get(
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname", [""]
)[0]
Expand Down

0 comments on commit 154fe90

Please sign in to comment.