authentik/passbook/sources/saml/xml_render.py

27 lines
742 B
Python
Raw Normal View History

2019-11-07 16:02:56 +00:00
"""Functions for creating XML output."""
from structlog import get_logger
from passbook.lib.utils.template import render_to_string
from passbook.providers.saml.utils.xml_signing import get_signature_xml
2019-11-07 16:02:56 +00:00
LOGGER = get_logger()
def get_authnrequest_xml(parameters, signed=False):
"""Get AuthN Request XML"""
# Reset signature.
params = {}
params.update(parameters)
2019-12-31 11:51:16 +00:00
params["AUTHN_REQUEST_SIGNATURE"] = ""
2019-11-07 16:02:56 +00:00
2019-12-31 11:51:16 +00:00
unsigned = render_to_string("saml/sp/xml/authn_request.xml", params)
2019-11-07 16:02:56 +00:00
if not signed:
return unsigned
# Sign it.
signature_xml = get_signature_xml()
2019-12-31 11:51:16 +00:00
params["AUTHN_REQUEST_SIGNATURE"] = signature_xml
signed = render_to_string("saml/sp/xml/authn_request.xml", params)
2019-11-07 16:02:56 +00:00
return signed