3 from html
import unescape
4 from urllib.parse
import urlparse
16 Obtains the SAML response from an Identity Provider
17 given the provided username and password.
22 The logon page of the SAML Identity Provider
28 The HTML form ID for the username
29 passwordformfield : str
30 The HTML form ID for the password
31 sslverify : bool, optional
32 Verify TLS certificates, by default True
35 session = requests.Session()
37 response = session.get(idpurl, verify=sslverify)
38 initialurl = response.url
39 formaction = initialurl
45 r'<form\s+.*?\s+action' r'\s*=\s*\"(.*?)\".*?<\s*/form>',
47 re.IGNORECASE | re.DOTALL,
51 formaction = asearch.group(1)
54 if not formaction.lower().startswith(
'http'):
55 parsedurl = urlparse(idpurl)
56 formaction = parsedurl.scheme +
"://" + parsedurl.netloc + formaction
61 formpayload = {userformfield: username, passwordformfield: password}
63 response = session.post(formaction, data=formpayload, verify=sslverify)
67 r'<input\s+.*?\s+name\s*=\s*'
68 r'\"SAMLResponse\".*?\s+value=\"(.*?)\".*?\/>',
70 re.IGNORECASE | re.DOTALL,
73 samlresponse = ssearch.group(1)
76 re.sub(
r"[\r\n\t\s]*",
"", samlresponse)
79 raise ValueError(
'No SAMLResponse found in response.')
std::string unescape(std::string s)