Api v1.13.0 release (#1346)
* fix(chalice): support SSO with custom port
This commit is contained in:
parent
d60d6ab487
commit
7271eacbdf
1 changed files with 10 additions and 6 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
from http import cookies
|
from http import cookies
|
||||||
from os import environ
|
from os import environ
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
@ -63,7 +64,7 @@ if SAML2["idp"] is None:
|
||||||
}
|
}
|
||||||
|
|
||||||
if idp is None:
|
if idp is None:
|
||||||
print("No SAML2 IdP configuration found")
|
logging.info("No SAML2 IdP configuration found")
|
||||||
else:
|
else:
|
||||||
SAML2["idp"] = idp
|
SAML2["idp"] = idp
|
||||||
|
|
||||||
|
|
@ -89,18 +90,21 @@ async def prepare_request(request: Request):
|
||||||
for key, morsel in cookie.items():
|
for key, morsel in cookie.items():
|
||||||
extracted_cookies[key] = morsel.value
|
extracted_cookies[key] = morsel.value
|
||||||
if "session" not in extracted_cookies:
|
if "session" not in extracted_cookies:
|
||||||
print("!!! session not found in extracted_cookies")
|
logging.info("!!! session not found in extracted_cookies")
|
||||||
print(extracted_cookies)
|
logging.info(extracted_cookies)
|
||||||
session = extracted_cookies.get("session", {})
|
session = extracted_cookies.get("session", {})
|
||||||
else:
|
else:
|
||||||
session = {}
|
session = {}
|
||||||
# If server is behind proxys or balancers use the HTTP_X_FORWARDED fields
|
# If server is behind proxys or balancers use the HTTP_X_FORWARDED fields
|
||||||
headers = request.headers
|
headers = request.headers
|
||||||
proto = headers.get('x-forwarded-proto', 'http')
|
proto = headers.get('x-forwarded-proto', 'http')
|
||||||
if headers.get('x-forwarded-proto') is not None:
|
|
||||||
print(f"x-forwarded-proto: {proto}")
|
|
||||||
url_data = urlparse('%s://%s' % (proto, headers['host']))
|
url_data = urlparse('%s://%s' % (proto, headers['host']))
|
||||||
path = request.url.path
|
path = request.url.path
|
||||||
|
site_url = urlparse(config("SITE_URL"))
|
||||||
|
host_suffix = ""
|
||||||
|
if site_url.port is not None and request.url.port is None:
|
||||||
|
host_suffix = f":{site_url.port}"
|
||||||
|
|
||||||
# add / to /acs
|
# add / to /acs
|
||||||
if not path.endswith("/"):
|
if not path.endswith("/"):
|
||||||
path = path + '/'
|
path = path + '/'
|
||||||
|
|
@ -109,7 +113,7 @@ async def prepare_request(request: Request):
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'https': 'on' if proto == 'https' else 'off',
|
'https': 'on' if proto == 'https' else 'off',
|
||||||
'http_host': request.headers['host'],
|
'http_host': request.headers['host'] + host_suffix,
|
||||||
'server_port': url_data.port,
|
'server_port': url_data.port,
|
||||||
'script_name': path,
|
'script_name': path,
|
||||||
'get_data': request.args.copy(),
|
'get_data': request.args.copy(),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue