Skip to content

Commit

Permalink
update send_saml_response to use http_client
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Aureliano da Silva Maia committed Oct 2, 2023
1 parent 4e7ca01 commit 369e0f3
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions tokendito/okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,47 @@ def send_saml_request(saml_request, cookies, user_agent=f"Tokendito/{__version__



def send_saml_response(saml_response):
"""Submit SAML response to the SP.
def send_saml_response(saml_response, user_agent = f"Tokendito/{__version__}"):
"""
Submit SAML response to the SP.
:param saml_response: dict with with SP post_url, relay_state, and saml_response
:param saml_response: dict with SP post_url, relay_state, and saml_response
:returns: `sid` session cookie
"""

# Create an HTTP client instance with the version-specific user agent.
http_client = HTTPClient(user_agent)

# Define the payload and headers for the request.
payload = {
"SAMLResponse": saml_response["response"],
"RelayState": saml_response["relay_state"],
}
headers = {"accept": "text/html,application/xhtml+xml,application/xml"}

# Construct the URL from the provided saml_response.
url = saml_response["post_url"]

# Log the SAML response details.
logger.debug(f"Sending SAML response back to {url}")
response = user.request_wrapper("POST", url, data=payload, headers=headers)

# Use the HTTP client to make a POST request.
response = http_client.post(url, data=payload, headers=headers)

# Extract cookies from the response.
session_cookies = response.cookies

# Get the 'sid' value from the cookies.
sid = session_cookies.get("sid")

# If 'sid' is present, mask its value for logging purposes.
if sid is not None:
user.add_sensitive_value_to_be_masked(sid)

# Log the session cookies.
logger.debug(f"Have session cookies: {session_cookies}")

# Return the session cookies.
return session_cookies


Expand Down

0 comments on commit 369e0f3

Please sign in to comment.