Skip to content

Commit e208dfd

Browse files
committed
Allow phase2 to specify signing algorithm; although unused atm
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 7352484 commit e208dfd

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/saml2/ecp_client.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,16 @@ def __init__(self, user, passwd, sp="", idp=None, metadata_file=None,
9191
self.done_ecp = False
9292
self.cookie_jar = cookielib.LWPCookieJar()
9393

94-
def phase2(self, authn_request, rc_url, idp_entity_id, headers=None,
95-
sign=False, **kwargs):
94+
def phase2(
95+
self,
96+
authn_request,
97+
rc_url,
98+
idp_entity_id,
99+
headers=None,
100+
sign=False,
101+
sign_alg=None,
102+
**kwargs,
103+
):
96104
"""
97105
Doing the second phase of the ECP conversation, the conversation
98106
with the IdP happens.
@@ -105,12 +113,13 @@ def phase2(self, authn_request, rc_url, idp_entity_id, headers=None,
105113
:return: The response from the IdP
106114
"""
107115

108-
_, destination = self.pick_binding("single_sign_on_service",
109-
[BINDING_SOAP], "idpsso",
110-
entity_id=idp_entity_id)
116+
_, destination = self.pick_binding(
117+
"single_sign_on_service", [BINDING_SOAP], "idpsso", entity_id=idp_entity_id
118+
)
111119

112-
ht_args = self.apply_binding(BINDING_SOAP, authn_request, destination,
113-
sign=sign)
120+
ht_args = self.apply_binding(
121+
BINDING_SOAP, authn_request, destination, sign=sign, sigalg=sign_alg
122+
)
114123

115124
if headers:
116125
ht_args["headers"].extend(headers)
@@ -124,8 +133,10 @@ def phase2(self, authn_request, rc_url, idp_entity_id, headers=None,
124133

125134
if response.status_code != 200:
126135
raise SAMLError(
127-
"Request to IdP failed (%s): %s" % (response.status_code,
128-
response.text))
136+
"Request to IdP failed ({status}): {text}".format(
137+
status=response.status_code, text=response.text
138+
)
139+
)
129140

130141
# SAMLP response in a SOAP envelope body, ecp response in headers
131142
respdict = self.parse_soap_message(response.text)
@@ -195,8 +206,11 @@ def parse_sp_ecp_response(respdict):
195206

196207
_rc_url = _paos_request.response_consumer_url
197208

198-
return {"authn_request": authn_request, "rc_url": _rc_url,
199-
"relay_state": _relay_state}
209+
return {
210+
"authn_request": authn_request,
211+
"rc_url": _rc_url,
212+
"relay_state": _relay_state,
213+
}
200214

201215
def ecp_conversation(self, respdict, idp_entity_id=None):
202216
"""
@@ -218,8 +232,7 @@ def ecp_conversation(self, respdict, idp_entity_id=None):
218232
# Phase 3 - back to the SP
219233
# **********************************
220234

221-
ht_args = self.use_soap(idp_response, args["rc_url"],
222-
[args["relay_state"]])
235+
ht_args = self.use_soap(idp_response, args["rc_url"], [args["relay_state"]])
223236
ht_args["headers"][0] = ('Content-Type', MIME_PAOS)
224237
logger.debug("[P3] Post to SP: %s", ht_args["data"])
225238

@@ -231,8 +244,7 @@ def ecp_conversation(self, respdict, idp_entity_id=None):
231244
# url I started off with.
232245
pass
233246
else:
234-
raise SAMLError(
235-
"Error POSTing package to SP: %s" % response.text)
247+
raise SAMLError("Error POSTing package to SP: %s" % response.text)
236248

237249
logger.debug("[P3] SP response: %s", response.text)
238250

0 commit comments

Comments
 (0)