Skip to content

Commit 8b69c35

Browse files
committed
Added support for receiving SAMLRequests on the single_logout endpoint
1 parent 11b777f commit 8b69c35

File tree

1 file changed

+21
-8
lines changed
  • src/s2repoze/plugins

1 file changed

+21
-8
lines changed

src/s2repoze/plugins/sp.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def identify(self, environ):
419419
#logger = environ.get('repoze.who.logger', '')
420420

421421
query = parse_dict_querystring(environ)
422-
if ("CONTENT_LENGTH" not in environ or not environ["CONTENT_LENGTH"]) and "SAMLResponse" not in query:
422+
if ("CONTENT_LENGTH" not in environ or not environ["CONTENT_LENGTH"]) and "SAMLResponse" not in query and "SAMLRequest" not in query:
423423
logger.debug('[identify] get or empty post')
424424
return {}
425425

@@ -434,7 +434,7 @@ def identify(self, environ):
434434
query = parse_dict_querystring(environ)
435435
logger.debug('[sp.identify] query: %s' % (query,))
436436

437-
if "SAMLResponse" in query:
437+
if "SAMLResponse" in query or "SAMLRequest" in query:
438438
post = query
439439
binding = BINDING_HTTP_REDIRECT
440440
else:
@@ -447,7 +447,21 @@ def identify(self, environ):
447447
pass
448448

449449
try:
450-
if "SAMLResponse" not in post:
450+
path_info = environ['PATH_INFO']
451+
logout = False
452+
if path_info in self.logout_endpoints:
453+
logout = True
454+
455+
if logout and "SAMLRequest" in post:
456+
print("logout request received")
457+
try:
458+
response = self.saml_client.handle_logout_request(post["SAMLRequest"], self.saml_client.users.subjects()[0], binding)
459+
environ['samlsp.pending'] = self._handle_logout(response)
460+
return {}
461+
except:
462+
import traceback
463+
traceback.print_exc()
464+
elif "SAMLResponse" not in post:
451465
logger.info("[sp.identify] --- NOT SAMLResponse ---")
452466
# Not for me, put the post back where next in line can
453467
# find it
@@ -457,10 +471,6 @@ def identify(self, environ):
457471
logger.info("[sp.identify] --- SAMLResponse ---")
458472
# check for SAML2 authN response
459473
#if self.debug:
460-
path_info = environ['PATH_INFO']
461-
logout = False
462-
if path_info in self.logout_endpoints:
463-
logout = True
464474
try:
465475
if logout:
466476
response = self.saml_client.parse_logout_request_response(post["SAMLResponse"], binding)
@@ -568,7 +578,10 @@ def authenticate(self, environ, identity=None):
568578
return None
569579

570580
def _handle_logout(self, responses):
571-
ht_args = responses[responses.keys()[0]][1]
581+
if 'data' in responses:
582+
ht_args = responses
583+
else:
584+
ht_args = responses[responses.keys()[0]][1]
572585
if not ht_args["data"] and ht_args["headers"][0][0] == "Location":
573586
logger.debug('redirect to: %s' % ht_args["headers"][0][1])
574587
return HTTPSeeOther(headers=ht_args["headers"])

0 commit comments

Comments
 (0)