Skip to content

Commit cd97e1f

Browse files
committed
Add get_last_authn_contexts method
1 parent 4f7add5 commit cd97e1f

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ Main class of OneLogin Python Toolkit
940940
* ***get_sso_url*** Gets the SSO url.
941941
* ***get_slo_url*** Gets the SLO url.
942942
* ***get_last_request_id*** The ID of the last Request SAML message generated (AuthNRequest, LogoutRequest).
943+
* ***get_last_authn_contexts*** Returns the list of authentication contexts sent in the last SAML Response.
943944
* ***build_request_signature*** Builds the Signature of the SAML Request.
944945
* ***build_response_signature*** Builds the Signature of the SAML Response.
945946
* ***get_settings*** Returns the settings info.

src/onelogin/saml2/auth.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ def redirect_to(self, url=None, parameters={}):
202202
url = self.__request_data['get_data']['RelayState']
203203
return OneLogin_Saml2_Utils.redirect(url, parameters, request_data=self.__request_data)
204204

205+
def get_last_authn_contexts(self):
206+
"""
207+
:returns: The list of authentication contexts sent in the last SAML Response.
208+
:rtype: list
209+
"""
210+
return self.__last_authn_contexts
211+
205212
def is_authenticated(self):
206213
"""
207214
Checks if the user is authenticated or not.

tests/src/OneLogin/saml2_tests/auth_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,19 @@ def testGetLastAuthnRequest(self):
10531053
)
10541054
self.assertIn(expectedFragment, auth.get_last_request_xml())
10551055

1056+
def testGetLastAuthnContexts(self):
1057+
settings = self.loadSettingsJSON()
1058+
request_data = self.get_request()
1059+
message = self.file_contents(join(self.data_path, 'responses', 'valid_response.xml.base64'))
1060+
del request_data['get_data']
1061+
request_data['post_data'] = {
1062+
'SAMLResponse': message
1063+
}
1064+
auth = OneLogin_Saml2_Auth(request_data, old_settings=settings)
1065+
1066+
auth.process_response()
1067+
self.assertEqual(auth.get_last_authn_contexts(), ['urn:oasis:names:tc:SAML:2.0:ac:classes:Password'])
1068+
10561069
def testGetLastLogoutRequest(self):
10571070
settings = self.loadSettingsJSON()
10581071
auth = OneLogin_Saml2_Auth({'http_host': 'localhost', 'script_name': 'thing'}, old_settings=settings)

0 commit comments

Comments
 (0)