@@ -419,7 +419,7 @@ def identify(self, environ):
419
419
#logger = environ.get('repoze.who.logger', '')
420
420
421
421
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 :
423
423
logger .debug ('[identify] get or empty post' )
424
424
return {}
425
425
@@ -434,7 +434,7 @@ def identify(self, environ):
434
434
query = parse_dict_querystring (environ )
435
435
logger .debug ('[sp.identify] query: %s' % (query ,))
436
436
437
- if "SAMLResponse" in query :
437
+ if "SAMLResponse" in query or "SAMLRequest" in query :
438
438
post = query
439
439
binding = BINDING_HTTP_REDIRECT
440
440
else :
@@ -447,7 +447,21 @@ def identify(self, environ):
447
447
pass
448
448
449
449
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 :
451
465
logger .info ("[sp.identify] --- NOT SAMLResponse ---" )
452
466
# Not for me, put the post back where next in line can
453
467
# find it
@@ -457,10 +471,6 @@ def identify(self, environ):
457
471
logger .info ("[sp.identify] --- SAMLResponse ---" )
458
472
# check for SAML2 authN response
459
473
#if self.debug:
460
- path_info = environ ['PATH_INFO' ]
461
- logout = False
462
- if path_info in self .logout_endpoints :
463
- logout = True
464
474
try :
465
475
if logout :
466
476
response = self .saml_client .parse_logout_request_response (post ["SAMLResponse" ], binding )
@@ -568,7 +578,10 @@ def authenticate(self, environ, identity=None):
568
578
return None
569
579
570
580
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 ]
572
585
if not ht_args ["data" ] and ht_args ["headers" ][0 ][0 ] == "Location" :
573
586
logger .debug ('redirect to: %s' % ht_args ["headers" ][0 ][1 ])
574
587
return HTTPSeeOther (headers = ht_args ["headers" ])
0 commit comments