4040import defusedxml .ElementTree
4141
4242NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/"
43- FORM_SPEC = """<form method="post" action="%s">
44- <input type="hidden" name="%s" value="%s" />
45- <input type="hidden" name="RelayState" value="%s" />
46- <input type="submit" value="Submit" />
47- </form>"""
4843
44+ FORM_SPEC = """\
45+ <!DOCTYPE html>
46+ <html>
47+ <head>
48+ <meta charset="utf-8" />
49+ </head>
50+ <body onload="document.forms[0].submit()">
51+ <noscript>
52+ <p>
53+ <strong>Note:</strong> Since your browser does not support JavaScript,
54+ you must press the Continue button once to proceed.
55+ </p>
56+ </noscript>
57+
58+ <form action="{action}" method="post">
59+ <div>
60+ <input type="hidden" name="RelayState" value="{relay_state}"/>
61+
62+ <input type="hidden" name="{saml_type}" value="{saml_response}"/>
63+ </div>
64+ <noscript>
65+ <div>
66+ <input type="submit" value="Continue"/>
67+ </div>
68+ </noscript>
69+ </form>
70+ </body>
71+ </html>"""
4972
5073def http_form_post_message (message , location , relay_state = "" ,
5174 typ = "SAMLRequest" , ** kwargs ):
@@ -58,8 +81,6 @@ def http_form_post_message(message, location, relay_state="",
5881 :param relay_state: for preserving and conveying state information
5982 :return: A tuple containing header information and a HTML message.
6083 """
61- response = ["<head>" , """<title>SAML 2.0 POST</title>""" , "</head><body>" ]
62-
6384 if not isinstance (message , six .string_types ):
6485 message = str (message )
6586 if not isinstance (message , six .binary_type ):
@@ -71,17 +92,17 @@ def http_form_post_message(message, location, relay_state="",
7192 _msg = message
7293 _msg = _msg .decode ('ascii' )
7394
74- response .append (FORM_SPEC % (location , typ , _msg , relay_state ))
95+ args = {
96+ 'action' : location ,
97+ 'saml_type' : typ ,
98+ 'relay_state' : relay_state ,
99+ 'saml_response' : _msg
100+ }
75101
76- response .append ("""<script type="text/javascript">""" )
77- response .append (" window.onload = function ()" )
78- response .append (" { document.forms[0].submit(); }" )
79- response .append ("""</script>""" )
80- response .append ("</body>" )
102+ response = FORM_SPEC .format (** args )
81103
82104 return {"headers" : [("Content-type" , "text/html" )], "data" : response }
83105
84-
85106def http_post_message (message , relay_state = "" , typ = "SAMLRequest" , ** kwargs ):
86107 """
87108
0 commit comments