2424from saml2 .time_util import not_on_or_after
2525from saml2 .saml import AssertionIDRef
2626from saml2 .client_base import Base
27+ from saml2 .client_base import SignOnError
2728from saml2 .client_base import LogoutError
2829from saml2 .client_base import NoServiceDefined
2930from saml2 .mdstore import destinations
3031
3132try :
32- from urlparse import parse_qs
33+ from urllib . parse import parse_qs
3334except ImportError :
34- # Compatibility with Python <= 2.5
35- from cgi import parse_qs
35+ from urlparse import parse_qs
3636
3737import logging
3838
4242class Saml2Client (Base ):
4343 """ The basic pySAML2 service provider class """
4444
45- def prepare_for_authenticate (self , entityid = None , relay_state = "" ,
46- binding = saml2 .BINDING_HTTP_REDIRECT , vorg = "" ,
47- nameid_format = None ,
48- scoping = None , consent = None , extensions = None ,
49- sign = None ,
50- response_binding = saml2 .BINDING_HTTP_POST ,
51- ** kwargs ):
45+ def prepare_for_authenticate (
46+ self , entityid = None , relay_state = "" ,
47+ binding = saml2 .BINDING_HTTP_REDIRECT , vorg = "" , nameid_format = None ,
48+ scoping = None , consent = None , extensions = None , sign = None ,
49+ response_binding = saml2 .BINDING_HTTP_POST , ** kwargs ):
5250 """ Makes all necessary preparations for an authentication request.
5351
5452 :param entityid: The entity ID of the IdP to send the request to
@@ -82,14 +80,12 @@ def prepare_for_authenticate(self, entityid=None, relay_state="",
8280
8381 return reqid , info
8482
85- def prepare_for_negotiated_authenticate (self , entityid = None , relay_state = "" ,
86- binding = None , vorg = "" ,
87- nameid_format = None ,
88- scoping = None , consent = None , extensions = None ,
89- sign = None ,
90- response_binding = saml2 .BINDING_HTTP_POST ,
91- ** kwargs ):
92- """ Makes all necessary preparations for an authentication request that negotiates
83+ def prepare_for_negotiated_authenticate (
84+ self , entityid = None , relay_state = "" , binding = None , vorg = "" ,
85+ nameid_format = None , scoping = None , consent = None , extensions = None ,
86+ sign = None , response_binding = saml2 .BINDING_HTTP_POST , ** kwargs ):
87+ """ Makes all necessary preparations for an authentication request
88+ that negotiates
9389 which binding to use for authentication.
9490
9591 :param entityid: The entity ID of the IdP to send the request to
@@ -117,20 +113,25 @@ def prepare_for_negotiated_authenticate(self, entityid=None, relay_state="",
117113
118114 reqid , request = self .create_authn_request (
119115 destination , vorg , scoping , response_binding , nameid_format ,
120- consent = consent ,
121- extensions = extensions , sign = sign ,
116+ consent = consent , extensions = extensions , sign = sign ,
122117 ** kwargs )
123118
124119 _req_str = str (request )
125120
126121 logger .info ("AuthNReq: %s" % _req_str )
127122
123+ try :
124+ sigalg = kwargs ["sigalg" ]
125+ except KeyError :
126+ sigalg = ""
127+
128128 http_info = self .apply_binding (binding , _req_str , destination ,
129- relay_state )
129+ relay_state , sigalg = sigalg )
130130
131131 return reqid , binding , http_info
132132 else :
133- raise SignOnError ("No supported bindings available for authentication" )
133+ raise SignOnError (
134+ "No supported bindings available for authentication" )
134135
135136 def global_logout (self , name_id , reason = "" , expire = None , sign = None ):
136137 """ More or less a layer of indirection :-/
@@ -206,7 +207,7 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
206207 destination , entity_id , name_id = name_id , reason = reason ,
207208 expire = expire )
208209
209- #to_sign = []
210+ # to_sign = []
210211 if binding .startswith ("http://" ):
211212 sign = True
212213
@@ -230,7 +231,8 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
230231 not_done .remove (entity_id )
231232 response = response .text
232233 logger .info ("Response: %s" % response )
233- res = self .parse_logout_request_response (response , binding )
234+ res = self .parse_logout_request_response (response ,
235+ binding )
234236 responses [entity_id ] = res
235237 else :
236238 logger .info ("NOT OK response from %s" % destination )
@@ -324,15 +326,15 @@ def _use_soap(self, destination, query_type, **kwargs):
324326 raise HTTPError ("%d:%s" % (response .status_code , response .error ))
325327
326328 if response :
327- #not_done.remove(entity_id)
329+ # not_done.remove(entity_id)
328330 logger .info ("OK response from %s" % destination )
329331 return response
330332 else :
331333 logger .info ("NOT OK response from %s" % destination )
332334
333335 return None
334336
335- #noinspection PyUnusedLocal
337+ # noinspection PyUnusedLocal
336338 def do_authz_decision_query (self , entity_id , action ,
337339 subject_id , nameid_format ,
338340 evidence = None , resource = None ,
0 commit comments