24
24
from saml2 .time_util import not_on_or_after
25
25
from saml2 .saml import AssertionIDRef
26
26
from saml2 .client_base import Base
27
+ from saml2 .client_base import SignOnError
27
28
from saml2 .client_base import LogoutError
28
29
from saml2 .client_base import NoServiceDefined
29
30
from saml2 .mdstore import destinations
30
31
31
32
try :
32
- from urlparse import parse_qs
33
+ from urllib . parse import parse_qs
33
34
except ImportError :
34
- # Compatibility with Python <= 2.5
35
- from cgi import parse_qs
35
+ from urlparse import parse_qs
36
36
37
37
import logging
38
38
42
42
class Saml2Client (Base ):
43
43
""" The basic pySAML2 service provider class """
44
44
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 ):
52
50
""" Makes all necessary preparations for an authentication request.
53
51
54
52
: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="",
82
80
83
81
return reqid , info
84
82
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
93
89
which binding to use for authentication.
94
90
95
91
: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="",
117
113
118
114
reqid , request = self .create_authn_request (
119
115
destination , vorg , scoping , response_binding , nameid_format ,
120
- consent = consent ,
121
- extensions = extensions , sign = sign ,
116
+ consent = consent , extensions = extensions , sign = sign ,
122
117
** kwargs )
123
118
124
119
_req_str = str (request )
125
120
126
121
logger .info ("AuthNReq: %s" % _req_str )
127
122
123
+ try :
124
+ sigalg = kwargs ["sigalg" ]
125
+ except KeyError :
126
+ sigalg = ""
127
+
128
128
http_info = self .apply_binding (binding , _req_str , destination ,
129
- relay_state )
129
+ relay_state , sigalg = sigalg )
130
130
131
131
return reqid , binding , http_info
132
132
else :
133
- raise SignOnError ("No supported bindings available for authentication" )
133
+ raise SignOnError (
134
+ "No supported bindings available for authentication" )
134
135
135
136
def global_logout (self , name_id , reason = "" , expire = None , sign = None ):
136
137
""" More or less a layer of indirection :-/
@@ -206,7 +207,7 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
206
207
destination , entity_id , name_id = name_id , reason = reason ,
207
208
expire = expire )
208
209
209
- #to_sign = []
210
+ # to_sign = []
210
211
if binding .startswith ("http://" ):
211
212
sign = True
212
213
@@ -230,7 +231,8 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
230
231
not_done .remove (entity_id )
231
232
response = response .text
232
233
logger .info ("Response: %s" % response )
233
- res = self .parse_logout_request_response (response , binding )
234
+ res = self .parse_logout_request_response (response ,
235
+ binding )
234
236
responses [entity_id ] = res
235
237
else :
236
238
logger .info ("NOT OK response from %s" % destination )
@@ -324,15 +326,15 @@ def _use_soap(self, destination, query_type, **kwargs):
324
326
raise HTTPError ("%d:%s" % (response .status_code , response .error ))
325
327
326
328
if response :
327
- #not_done.remove(entity_id)
329
+ # not_done.remove(entity_id)
328
330
logger .info ("OK response from %s" % destination )
329
331
return response
330
332
else :
331
333
logger .info ("NOT OK response from %s" % destination )
332
334
333
335
return None
334
336
335
- #noinspection PyUnusedLocal
337
+ # noinspection PyUnusedLocal
336
338
def do_authz_decision_query (self , entity_id , action ,
337
339
subject_id , nameid_format ,
338
340
evidence = None , resource = None ,
0 commit comments