Skip to content

Commit d4be3be

Browse files
committed
Be able to retrieve Session Timeout after processResponse
1 parent 590e5ae commit d4be3be

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/onelogin/saml2/auth.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(self, request_data, old_settings=None, custom_base_path=None):
5454
self.__attributes = []
5555
self.__nameid = None
5656
self.__session_index = None
57+
self.__session_expiration = None
5758
self.__authenticated = False
5859
self.__errors = []
5960
self.__error_reason = None
@@ -95,6 +96,7 @@ def process_response(self, request_id=None):
9596
self.__attributes = response.get_attributes()
9697
self.__nameid = response.get_nameid()
9798
self.__session_index = response.get_session_index()
99+
self.__session_expiration = response.get_session_not_on_or_after()
98100
self.__authenticated = True
99101

100102
else:
@@ -213,6 +215,14 @@ def get_session_index(self):
213215
"""
214216
return self.__session_index
215217

218+
def get_session_expiration(self):
219+
"""
220+
Returns the SessionNotOnOrAfter from the AuthnStatement.
221+
:returns: The SessionNotOnOrAfter of the assertion
222+
:rtype: DateTime|null
223+
"""
224+
return self.__session_expiration
225+
216226
def get_errors(self):
217227
"""
218228
Returns a list with code errors if something went wrong

tests/src/OneLogin/saml2_tests/auth_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ def testGetSessionIndex(self):
9696
auth2.process_response()
9797
self.assertEqual('_6273d77b8cde0c333ec79d22a9fa0003b9fe2d75cb', auth2.get_session_index())
9898

99+
def testGetSessionExpiration(self):
100+
"""
101+
Tests the get_session_expiration method of the OneLogin_Saml2_Auth class
102+
"""
103+
settings_info = self.loadSettingsJSON()
104+
auth = OneLogin_Saml2_Auth(self.get_request(), old_settings=settings_info)
105+
self.assertIsNone(auth.get_session_expiration())
106+
107+
request_data = self.get_request()
108+
message = self.file_contents(join(self.data_path, 'responses', 'valid_response.xml.base64'))
109+
del request_data['get_data']
110+
request_data['post_data'] = {
111+
'SAMLResponse': message
112+
}
113+
auth2 = OneLogin_Saml2_Auth(request_data, old_settings=self.loadSettingsJSON())
114+
self.assertIsNone(auth2.get_session_expiration())
115+
116+
auth2.process_response()
117+
self.assertEqual(1392802621, auth2.get_session_expiration())
118+
99119
def testGetLastErrorReason(self):
100120
"""
101121
Tests the get_last_error_reason method of the OneLogin_Saml2_Auth class

0 commit comments

Comments
 (0)