Skip to content

Commit e754433

Browse files
committed
[fix] Remove dependency on RelayState for IdP-initiated login
1 parent 9ba1c5d commit e754433

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

django_saml2_auth/views.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,17 @@ def acs(request: HttpRequest):
6969
# If RelayState params is passed, it is a JWT token that identifies the user trying to login
7070
# via sp_initiated_login endpoint
7171
relay_state = request.POST.get("RelayState")
72-
redirected_user_id = None
73-
saml_resp_user_id = get_user_id(user)
7472
if relay_state:
7573
redirected_user_id = decode_jwt_token(relay_state)
7674

77-
# This prevents users from entering an email on the SP, but use a different email on IdP
78-
if saml_resp_user_id != redirected_user_id:
79-
raise SAMLAuthError("The user identifier doesn't match.", extra={
80-
"exc_type": ValueError,
81-
"error_code": USER_MISMATCH,
82-
"reason": "User identifier mismatch.",
83-
"status_code": 403
84-
})
75+
# This prevents users from entering an email on the SP, but use a different email on IdP
76+
if get_user_id(user) != redirected_user_id:
77+
raise SAMLAuthError("The user identifier doesn't match.", extra={
78+
"exc_type": ValueError,
79+
"error_code": USER_MISMATCH,
80+
"reason": "User identifier mismatch.",
81+
"status_code": 403
82+
})
8583

8684
is_new_user, target_user = get_or_create_user(user)
8785

0 commit comments

Comments
 (0)