Skip to content

Commit b9f9a4e

Browse files
committed
On a LogoutRequest if the NameIdFormat is entity, NameQualifier and SPNameQualifier will be ommited. If the NameIdFormat is not entity and a NameQualifier is provided, then the SPNameQualifier will be also added. Update info related to LogoutRequest on the README
1 parent 16cd67c commit b9f9a4e

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,15 +765,23 @@ target_url = 'https://example.com'
765765
auth.logout(return_to=target_url)
766766
```
767767

768-
Also there are 2 optional parameters that can be set:
768+
Also there are 4 optional parameters that can be set:
769769

770770
* name_id. That will be used to build the LogoutRequest. If not name_id parameter is set and the auth object processed a
771771
SAML Response with a NameId, then this NameId will be used.
772772
* session_index. SessionIndex that identifies the session of the user.
773+
* nq. IDP Name Qualifier
774+
* name_id_format. The NameID Format that will be set in the LogoutRequest
775+
776+
If no name_id is provided, the LogoutRequest will contain a NameID with the entity Format.
777+
If name_id is provided and no name_id_format is provided, the NameIDFormat of the settings will be used.
778+
If nq is provided, the SPNameQualifier will be also attached to the NameId.
773779

774780
If a match on the LogoutResponse ID and the LogoutRequest ID to be sent is required, that LogoutRequest ID must to be extracted and stored for future validation, we can get that ID by
775781

782+
```python
776783
auth.get_last_request_id()
784+
```
777785

778786
####Example of a view that initiates the SSO request and handles the response (is the acs target)####
779787

src/onelogin/saml2/logout_request.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@ def __init__(self, settings, request=None, name_id=None, session_index=None, nq=
7272
cert = idp_data['x509cert']
7373

7474
if name_id is not None:
75-
if name_id_format is None:
75+
if not name_id_format:
7676
name_id_format = sp_data['NameIDFormat']
77-
sp_name_qualifier = None
7877
else:
79-
name_id = idp_data['entityId']
8078
name_id_format = OneLogin_Saml2_Constants.NAMEID_ENTITY
79+
80+
sp_name_qualifier = None
81+
if name_id_format == OneLogin_Saml2_Constants.NAMEID_ENTITY:
82+
name_id = idp_data['entityId']
83+
nq = None
84+
elif nq is not None:
85+
# We only gonna include SPNameQualifier if NameQualifier is provided
8186
sp_name_qualifier = sp_data['entityId']
8287

8388
name_id_obj = OneLogin_Saml2_Utils.generate_name_id(

tests/src/OneLogin/saml2_tests/auth_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ def testGetLastLogoutRequest(self):
12231223
expectedFragment = (
12241224
' Destination="http://idp.example.com/SingleLogoutService.php">\n'
12251225
' <saml:Issuer>http://stuff.com/endpoints/metadata.php</saml:Issuer>\n'
1226-
' <saml:NameID SPNameQualifier="http://stuff.com/endpoints/metadata.php" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">http://idp.example.com/</saml:NameID>\n'
1226+
' <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">http://idp.example.com/</saml:NameID>\n'
12271227
' \n</samlp:LogoutRequest>'
12281228
)
12291229
self.assertIn(expectedFragment, auth.get_last_request_xml())

tests/src/OneLogin/saml2_tests/logout_request_test.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,30 @@ def testGetNameIdData(self):
157157
expected_name_id_data = {
158158
'Format': 'urn:oasis:names:tc:SAML:2.0:nameid-format:emailAddress',
159159
'NameQualifier': idp_data['entityId'],
160+
'SPNameQualifier': 'http://stuff.com/endpoints/metadata.php',
160161
'Value': 'ONELOGIN_9c86c4542ab9d6fce07f2f7fd335287b9b3cdf69'
161162
}
162163

163164
logout_request = OneLogin_Saml2_Logout_Request(settings, None, expected_name_id_data['Value'], None, idp_data['entityId'], expected_name_id_data['Format'])
164165
name_id_data_3 = OneLogin_Saml2_Logout_Request.get_nameid_data(logout_request.get_xml())
165166
self.assertEqual(expected_name_id_data, name_id_data_3)
166167

168+
expected_name_id_data = {
169+
'Format': 'urn:oasis:names:tc:SAML:2.0:nameid-format:emailAddress',
170+
'Value': 'ONELOGIN_9c86c4542ab9d6fce07f2f7fd335287b9b3cdf69'
171+
}
172+
logout_request = OneLogin_Saml2_Logout_Request(settings, None, expected_name_id_data['Value'], None, None, expected_name_id_data['Format'])
173+
name_id_data_4 = OneLogin_Saml2_Logout_Request.get_nameid_data(logout_request.get_xml())
174+
self.assertEqual(expected_name_id_data, name_id_data_4)
175+
176+
expected_name_id_data = {
177+
'Format': 'urn:oasis:names:tc:SAML:2.0:nameid-format:entity',
178+
'Value': 'http://idp.example.com/'
179+
}
180+
logout_request = OneLogin_Saml2_Logout_Request(settings)
181+
name_id_data_5 = OneLogin_Saml2_Logout_Request.get_nameid_data(logout_request.get_xml())
182+
self.assertEqual(expected_name_id_data, name_id_data_5)
183+
167184
def testGetNameId(self):
168185
"""
169186
Tests the get_nameid of the OneLogin_Saml2_LogoutRequest
@@ -367,7 +384,7 @@ def testGetXML(self):
367384
expectedFragment = (
368385
'Destination="http://idp.example.com/SingleLogoutService.php">\n'
369386
' <saml:Issuer>http://stuff.com/endpoints/metadata.php</saml:Issuer>\n'
370-
' <saml:NameID SPNameQualifier="http://stuff.com/endpoints/metadata.php" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">http://idp.example.com/</saml:NameID>\n'
387+
' <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">http://idp.example.com/</saml:NameID>\n'
371388
' \n</samlp:LogoutRequest>'
372389
)
373390
self.assertIn(expectedFragment, logout_request_generated.get_xml())

0 commit comments

Comments
 (0)