diff --git a/environment.yml b/environment.yml index 9c36689..896305c 100644 --- a/environment.yml +++ b/environment.yml @@ -15,3 +15,4 @@ dependencies: - pytest-cov - pytest-mock - rbc +- requests diff --git a/pymapd/_samlutils.py b/pymapd/_samlutils.py new file mode 100644 index 0000000..5c057ba --- /dev/null +++ b/pymapd/_samlutils.py @@ -0,0 +1,77 @@ +import re +import requests +from html import unescape +from urllib.parse import urlparse + + +def get_saml_response(idpurl, + username, + password, + userformfield, + passwordformfield, + sslverify=True): + """ + Obtains the SAML response from an Identity Provider + given the provided username and password. + + Parameters + ---------- + idpurl : str + The logon page of the SAML Identity Provider + username : str + SAML Username + password : str + SAML Password + userformfield : str + The HTML form ID for the username + passwordformfield : str + The HTML form ID for the password + sslverify : bool, optional + Verify TLS certificates, by default True + """ + + session = requests.Session() + + response = session.get(idpurl, verify=sslverify) + initialurl = response.url + formaction = initialurl + # print(page.content) + + # Determine if there's an action in the form, if there is, + # use it instead of the page URL + asearch = re.search(r'