-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental SAML authentication option (#306)
* Fixes for boolean na types, typos, na assignments in test cases (#110) (#3) * Fix na types for boolean, fix test case na types, fillna prior to boolean Thrift cast to prevent type error * Attempt to distinguish int from bigint when int column contains None, fix int64 test that was actually an in32 test, add int32 test case * Fix linting issue * Sync from source repo master (#4) * Fixes for boolean na types, typos, na assignments in test cases (#110) * Fix na types for boolean, fix test case na types, fillna prior to boolean Thrift cast to prevent type error * Attempt to distinguish int from bigint when int column contains None, fix int64 test that was actually an in32 test, add int32 test case * Fix linting issue * Option to chunk Pandas columnar data load (#117) * Fixes for boolean na types, typos, na assignments in test cases (#110) (#3) * Fix na types for boolean, fix test case na types, fillna prior to boolean Thrift cast to prevent type error * Attempt to distinguish int from bigint when int column contains None, fix int64 test that was actually an in32 test, add int32 test case * Fix linting issue * Add option for chunking a Pandas columnar data load * Fix linting issues * Reorder options * Reorder options * Add ability to authenticate via SAML * Update dependencies * Add ability to authenticate via SAML Update dependencies * Add numba as a requirement * fixup: remove incorrect docstring Co-authored-by: JP <[email protected]>
- Loading branch information
Showing
4 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ dependencies: | |
- pytest-cov | ||
- pytest-mock | ||
- rbc | ||
- requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'<form\s+.*?\s+action' | ||
r'\s*=\s*\"(.*?)\".*?<\s*/form>', | ||
response.text, re.IGNORECASE | re.DOTALL) | ||
|
||
if asearch: | ||
formaction = asearch.group(1) | ||
|
||
# If the action is a path not a URL, build the full | ||
if not formaction.lower().startswith('http'): | ||
parsedurl = urlparse(idpurl) | ||
formaction = parsedurl.scheme + "://" + parsedurl.netloc + formaction | ||
|
||
# Un-urlencode the URL | ||
formaction = unescape(formaction) | ||
|
||
formpayload = { | ||
userformfield: username, | ||
passwordformfield: password | ||
} | ||
|
||
response = session.post(formaction, data=formpayload, verify=sslverify) | ||
|
||
samlresponse = None | ||
ssearch = re.search(r'<input\s+.*?\s+name\s*=\s*' | ||
r'\"SAMLResponse\".*?\s+value=\"(.*?)\".*?\/>', | ||
response.text, re.IGNORECASE | re.DOTALL) | ||
if ssearch: | ||
samlresponse = ssearch.group(1) | ||
# Remove any whitespace, some providers include | ||
# new lines in the response (!) | ||
re.sub(r"[\r\n\t\s]*", "", samlresponse) | ||
|
||
if not samlresponse: | ||
raise ValueError('No SAMLResponse found in response.') | ||
|
||
return samlresponse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters