Skip to content

Commit 73ee977

Browse files
committed
Add support for retrieving the last ID of the generated AuthNRequest / LogoutRequest
1 parent 9ea32f5 commit 73ee977

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ The login method can recieve 3 more optional parameters:
523523
* is_passive When true the AuthNReuqest will set the Ispassive='true'
524524
* set_nameid_policy When true the AuthNReuqest will set a nameIdPolicy element.
525525

526+
If a match on the future SAMLResponse ID and the AuthNRequest ID to be sent is required, that AuthNRequest ID must to be extracted and stored for future validation, we can get that ID by
527+
528+
auth.get_last_request_id()
529+
526530
#### The SP Endpoints ####
527531

528532
Related to the SP there are 3 important endpoints: The metadata view, the ACS view and the SLS view.
@@ -706,6 +710,10 @@ Also there are 2 optional parameters that can be set:
706710
SAML Response with a NameId, then this NameId will be used.
707711
* session_index. SessionIndex that identifies the session of the user.
708712

713+
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
714+
715+
auth.get_last_request_id()
716+
709717
####Example of a view that initiates the SSO request and handles the response (is the acs target)####
710718

711719
We can code a unique file that initiates the SSO process, handle the response, get the attributes, initiate the slo and processes the logout response.
@@ -781,6 +789,7 @@ Main class of OneLogin Python Toolkit
781789
* ***get_last_error_reason*** Returns the reason of the last error
782790
* ***get_sso_url*** Gets the SSO url.
783791
* ***get_slo_url*** Gets the SLO url.
792+
* ***get_last_request_id*** The ID of the last Request SAML message generated (AuthNRequest, LogoutRequest).
784793
* ***build_request_signature*** Builds the Signature of the SAML Request.
785794
* ***build_response_signature*** Builds the Signature of the SAML Response.
786795
* ***get_settings*** Returns the settings info.

src/onelogin/saml2/auth.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(self, request_data, old_settings=None, custom_base_path=None):
5858
self.__authenticated = False
5959
self.__errors = []
6060
self.__error_reason = None
61+
self.__last_request_id = None
6162

6263
def get_settings(self):
6364
"""
@@ -260,6 +261,13 @@ def get_attribute(self, name):
260261
assert isinstance(name, compat.str_type)
261262
return self.__attributes.get(name)
262263

264+
def get_last_request_id(self):
265+
"""
266+
:returns: The ID of the last Request SAML message generated.
267+
:rtype: string
268+
"""
269+
return self.__last_request_id
270+
263271
def login(self, return_to=None, force_authn=False, is_passive=False, set_nameid_policy=True):
264272
"""
265273
Initiates the SSO process.
@@ -280,6 +288,7 @@ def login(self, return_to=None, force_authn=False, is_passive=False, set_nameid_
280288
:rtype: string
281289
"""
282290
authn_request = OneLogin_Saml2_Authn_Request(self.__settings, force_authn, is_passive, set_nameid_policy)
291+
self.__last_request_id = authn_request.get_id()
283292

284293
saml_request = authn_request.get_request()
285294
parameters = {'SAMLRequest': saml_request}
@@ -328,6 +337,7 @@ def logout(self, return_to=None, name_id=None, session_index=None, nq=None):
328337
session_index=session_index,
329338
nq=nq
330339
)
340+
self.__last_request_id = logout_request.id
331341

332342
parameters = {'SAMLRequest': logout_request.get_request()}
333343
if return_to is not None:

0 commit comments

Comments
 (0)