Skip to content

Commit b6ffc59

Browse files
committed
Implement get_last_response_in_response_to()
1 parent ab62b0d commit b6ffc59

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ Main class of OneLogin Python Toolkit
967967
* ***set_strict*** Set the strict mode active/disable.
968968
* ***get_last_request_xml*** Returns the most recently-constructed/processed XML SAML request (``AuthNRequest``, ``LogoutRequest``)
969969
* ***get_last_response_xml*** Returns the most recently-constructed/processed XML SAML response (``SAMLResponse``, ``LogoutResponse``). If the SAMLResponse had an encrypted assertion, decrypts it.
970+
* ***get_last_response_in_response_to*** The `InResponseTo` of the most recently processed SAML Response.
970971
* ***get_last_message_id*** The ID of the last Response SAML message processed.
971972
* ***get_last_assertion_id*** The ID of the last assertion processed.
972973
* ***get_last_assertion_not_on_or_after*** The ``NotOnOrAfter`` value of the valid ``SubjectConfirmationData`` node (if any) of the last assertion processed (is only calculated with strict = true)

src/onelogin/saml2/auth.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(self, request_data, old_settings=None, custom_base_path=None):
7575
self._last_authn_contexts = []
7676
self._last_request = None
7777
self._last_response = None
78+
self._last_response_in_response_to = None
7879
self._last_assertion_not_on_or_after = None
7980

8081
def get_settings(self):
@@ -109,6 +110,7 @@ def store_valid_response(self, response):
109110
self._last_assertion_issue_instant = response.get_assertion_issue_instant()
110111
self._last_authn_contexts = response.get_authn_contexts()
111112
self._authenticated = True
113+
self._last_response_in_response_to = response.get_in_response_to()
112114
self._last_assertion_not_on_or_after = response.get_assertion_not_on_or_after()
113115

114116
def process_response(self, request_id=None):
@@ -389,6 +391,13 @@ def get_last_authn_contexts(self):
389391
"""
390392
return self._last_authn_contexts
391393

394+
def get_last_response_in_response_to(self):
395+
"""
396+
:returns: InResponseTo attribute of the last Response SAML processed or None if it is not present.
397+
:rtype: string
398+
"""
399+
return self._last_response_in_response_to
400+
392401
def login(self, return_to=None, force_authn=False, is_passive=False, set_nameid_policy=True, name_id_value_req=None):
393402
"""
394403
Initiates the SSO process.

tests/src/OneLogin/saml2_tests/auth_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ def testGetLastLogoutResponse(self):
14151415

14161416
def testGetInfoFromLastResponseReceived(self):
14171417
"""
1418-
Tests the get_last_message_id, get_last_assertion_id, get_last_assertion_not_on_or_after and get_last_assertion_issue_instant
1418+
Tests the get_last_response_in_response_to, get_last_message_id, get_last_assertion_id, get_last_assertion_not_on_or_after and get_last_assertion_issue_instant
14191419
of the OneLogin_Saml2_Auth class
14201420
"""
14211421
settings = self.loadSettingsJSON()
@@ -1428,6 +1428,7 @@ def testGetInfoFromLastResponseReceived(self):
14281428
auth = OneLogin_Saml2_Auth(request_data, old_settings=settings)
14291429

14301430
auth.process_response()
1431+
self.assertEqual(auth.get_last_response_in_response_to(), 'ONELOGIN_5fe9d6e499b2f0913206aab3f7191729049bb807')
14311432
self.assertEqual(auth.get_last_message_id(), 'pfx42be40bf-39c3-77f0-c6ae-8bf2e23a1a2e')
14321433
self.assertEqual(auth.get_last_assertion_id(), 'pfx57dfda60-b211-4cda-0f63-6d5deb69e5bb')
14331434
self.assertIsNone(auth.get_last_assertion_not_on_or_after())
@@ -1440,6 +1441,7 @@ def testGetInfoFromLastResponseReceived(self):
14401441
auth = OneLogin_Saml2_Auth(request_data, old_settings=settings)
14411442
auth.process_response()
14421443
self.assertNotEqual(len(auth.get_errors()), 0)
1444+
self.assertIsNone(auth.get_last_response_in_response_to())
14431445
self.assertIsNone(auth.get_last_message_id())
14441446
self.assertIsNone(auth.get_last_assertion_id())
14451447
self.assertIsNone(auth.get_last_assertion_not_on_or_after())
@@ -1451,6 +1453,7 @@ def testGetInfoFromLastResponseReceived(self):
14511453
auth = OneLogin_Saml2_Auth(request_data, old_settings=settings)
14521454
auth.process_response()
14531455
self.assertEqual(len(auth.get_errors()), 0)
1456+
self.assertEqual(auth.get_last_response_in_response_to(), 'ONELOGIN_5fe9d6e499b2f0913206aab3f7191729049bb807')
14541457
self.assertEqual(auth.get_last_message_id(), 'pfx42be40bf-39c3-77f0-c6ae-8bf2e23a1a2e')
14551458
self.assertEqual(auth.get_last_assertion_id(), 'pfx57dfda60-b211-4cda-0f63-6d5deb69e5bb')
14561459
self.assertEqual(auth.get_last_assertion_not_on_or_after(), 2671081021)

0 commit comments

Comments
 (0)