providers/saml: fix RelayState being included when None given

This commit is contained in:
Jens Langhammer 2020-07-12 17:22:14 +02:00
parent 464b558a02
commit be6f342e58
1 changed files with 13 additions and 11 deletions

View File

@ -188,26 +188,28 @@ class SAMLFlowFinalView(StageView):
).build_response() ).build_response()
if provider.sp_binding == SAMLBindings.POST: if provider.sp_binding == SAMLBindings.POST:
form_attrs = {
"ACSUrl": provider.acs_url,
REQUEST_KEY_SAML_RESPONSE: nice64(response.encode()),
}
if auth_n_request.relay_state:
form_attrs[REQUEST_KEY_RELAY_STATE] = auth_n_request.relay_state
return render( return render(
self.request, self.request,
"generic/autosubmit_form.html", "generic/autosubmit_form.html",
{ {
"url": provider.acs_url, "url": provider.acs_url,
"title": _("Redirecting to %(app)s..." % {"app": application.name}), "title": _("Redirecting to %(app)s..." % {"app": application.name}),
"attrs": { "attrs": form_attrs,
"ACSUrl": provider.acs_url,
REQUEST_KEY_SAML_RESPONSE: nice64(response.encode()),
REQUEST_KEY_RELAY_STATE: auth_n_request.relay_state,
},
}, },
) )
if provider.sp_binding == SAMLBindings.REDIRECT: if provider.sp_binding == SAMLBindings.REDIRECT:
querystring = urlencode( url_args = {
{
REQUEST_KEY_SAML_RESPONSE: nice64(response.encode()), REQUEST_KEY_SAML_RESPONSE: nice64(response.encode()),
REQUEST_KEY_RELAY_STATE: auth_n_request.relay_state,
} }
) if auth_n_request.relay_state:
url_args[REQUEST_KEY_RELAY_STATE] = auth_n_request.relay_state
querystring = urlencode(url_args)
return redirect(f"{provider.acs_url}?{querystring}") return redirect(f"{provider.acs_url}?{querystring}")
return bad_request_message(request, "Invalid sp_binding specified") return bad_request_message(request, "Invalid sp_binding specified")