only formatting hopefully

This commit is contained in:
i 2026-02-06 17:42:40 +01:00
parent 025c87216d
commit 8ad5f1964e
9 changed files with 241 additions and 198 deletions

View file

@ -10,27 +10,28 @@ class KITProvider(SSOProvider):
domain = "kit.edu"
def authenticate(self) -> str:
self.session.headers.pop('x-requested-with', None)
self.session.headers.pop('x-inertia', None)
self.session.headers.pop('x-inertia-version', None)
self.session.headers.pop("x-requested-with", None)
self.session.headers.pop("x-inertia", None)
self.session.headers.pop("x-inertia-version", None)
csrf_token = extract_html_value(
self.redirect_response.text,
r'name="csrf_token" value="([^"]+)"'
self.redirect_response.text, r'name="csrf_token" value="([^"]+)"'
)
response = self.session.post(
'https://idp.scc.kit.edu/idp/profile/SAML2/Redirect/SSO?execution=e1s1',
"https://idp.scc.kit.edu/idp/profile/SAML2/Redirect/SSO?execution=e1s1",
data={
'csrf_token': csrf_token,
'j_username': self.username,
'j_password': self.password,
'_eventId_proceed': '',
'fudis_web_authn_assertion_input': '',
}
"csrf_token": csrf_token,
"j_username": self.username,
"j_password": self.password,
"_eventId_proceed": "",
"fudis_web_authn_assertion_input": "",
},
)
if "/consume" not in html.unescape(response.text):
raise ValueError("KIT authentication failed - invalid credentials or SSO error")
raise ValueError(
"KIT authentication failed - invalid credentials or SSO error"
)
return response.text

View file

@ -1,4 +1,3 @@
import html,sys
from auth.providers.base import SSOProvider
from utils.helpers import extract_html_value
@ -18,58 +17,55 @@ class TUMProvider(SSOProvider):
# 1. do one post to e1s1
# 2. do post to e1s2 with login data
# ->
self.session.headers.pop('x-requested-with', None)
self.session.headers.pop('x-inertia', None)
self.session.headers.pop('x-inertia-version', None)
self.session.headers.pop("x-requested-with", None)
self.session.headers.pop("x-inertia", None)
self.session.headers.pop("x-inertia-version", None)
csrf_token1 = extract_html_value(
self.redirect_response.text,
r'name="csrf_token" value="([^"]+)"'
self.redirect_response.text, r'name="csrf_token" value="([^"]+)"'
)
response1 = self.session.post(
# 'https://idp.scc.kit.edu/idp/profile/SAML2/Redirect/SSO?execution=e1s1',
'https://login.tum.de/idp/profile/SAML2/Redirect/SSO?execution=e1s1',
"https://login.tum.de/idp/profile/SAML2/Redirect/SSO?execution=e1s1",
data={
'csrf_token': csrf_token1,
'shib_idp_ls_exception.shib_idp_session_ss': '',
'shib_idp_ls_success.shib_idp_session_ss': 'true',
'shib_idp_ls_value.shib_idp_session_ss': '',
'shib_idp_ls_exception.shib_idp_persistent_ss': '',
'shib_idp_ls_success.shib_idp_persistent_ss': 'true',
'shib_idp_ls_value.shib_idp_persistent_ss': '',
'shib_idp_ls_supported': 'true',
'_eventId_proceed': '',
}
"csrf_token": csrf_token1,
"shib_idp_ls_exception.shib_idp_session_ss": "",
"shib_idp_ls_success.shib_idp_session_ss": "true",
"shib_idp_ls_value.shib_idp_session_ss": "",
"shib_idp_ls_exception.shib_idp_persistent_ss": "",
"shib_idp_ls_success.shib_idp_persistent_ss": "true",
"shib_idp_ls_value.shib_idp_persistent_ss": "",
"shib_idp_ls_supported": "true",
"_eventId_proceed": "",
},
)
# print(response1.text)
csrf_token2 = extract_html_value(
response1.text,
r'name="csrf_token" value="([^"]+)"'
response1.text, r'name="csrf_token" value="([^"]+)"'
)
response2 = self.session.post(
'https://login.tum.de/idp/profile/SAML2/Redirect/SSO?execution=e1s2',
"https://login.tum.de/idp/profile/SAML2/Redirect/SSO?execution=e1s2",
data={
'csrf_token': csrf_token2,
'j_username': self.username,
'j_password': self.password,
'donotcache': '1',
'_eventId_proceed': '',
}
"csrf_token": csrf_token2,
"j_username": self.username,
"j_password": self.password,
"donotcache": "1",
"_eventId_proceed": "",
},
)
# print(response2.text)
saml_response = extract_html_value(
response2.text,
r'name="SAMLResponse" value="([^"]+)"'
response2.text, r'name="SAMLResponse" value="([^"]+)"'
)
if len(saml_response)<3:
if len(saml_response) < 3:
raise ValueError("TUM auth no work:(")
else:
print("nice we got saml response starting with: "+saml_response[0:49])
print("nice we got saml response starting with: " + saml_response[0:49])
return response2.text
# print(saml_response)
# sys.exit()

View file

@ -35,29 +35,39 @@ class AnnySession:
return None
def _init_headers(self):
self.session.headers.update({
**DEFAULT_HEADERS,
'accept': 'text/html, application/xhtml+xml',
'referer': AUTH_BASE_URL + '/',
'origin': AUTH_BASE_URL
})
self.session.headers.update(
{
**DEFAULT_HEADERS,
"accept": "text/html, application/xhtml+xml",
"referer": AUTH_BASE_URL + "/",
"origin": AUTH_BASE_URL,
}
)
def _sso_login(self):
r1 = self.session.get(f"{AUTH_BASE_URL}/login/sso")
self.session.headers['X-XSRF-TOKEN'] = urllib.parse.unquote(r1.cookies['XSRF-TOKEN'])
self.session.headers["X-XSRF-TOKEN"] = urllib.parse.unquote(
r1.cookies["XSRF-TOKEN"]
)
page_data = extract_html_value(r1.text, r'data-page="(.*?)"')
version = re.search(r'"version"\s*:\s*"([a-f0-9]{32})"', page_data)
x_inertia_version = version.group(1) if version else '66b32acea13402d3aef4488ccd239c93'
x_inertia_version = (
version.group(1) if version else "66b32acea13402d3aef4488ccd239c93"
)
self.session.headers.update({
'x-requested-with': 'XMLHttpRequest',
'x-inertia': 'true',
'x-inertia-version': x_inertia_version
})
self.session.headers.update(
{
"x-requested-with": "XMLHttpRequest",
"x-inertia": "true",
"x-inertia-version": x_inertia_version,
}
)
r2 = self.session.post(f"{AUTH_BASE_URL}/login/sso", json={"domain": self.provider.domain})
redirect_url = r2.headers['x-inertia-location']
r2 = self.session.post(
f"{AUTH_BASE_URL}/login/sso", json={"domain": self.provider.domain}
)
redirect_url = r2.headers["x-inertia-location"]
redirect_response = self.session.get(redirect_url)
# Pass session and redirect response to provider
@ -69,13 +79,20 @@ class AnnySession:
self.saml_response_html = self.provider.authenticate()
def _consume_saml(self):
consume_url = extract_html_value(self.saml_response_html, r'form action="([^"]+)"')
relay_state = extract_html_value(self.saml_response_html, r'name="RelayState" value="([^"]+)"')
saml_response = extract_html_value(self.saml_response_html, r'name="SAMLResponse" value="([^"]+)"')
consume_url = extract_html_value(
self.saml_response_html, r'form action="([^"]+)"'
)
relay_state = extract_html_value(
self.saml_response_html, r'name="RelayState" value="([^"]+)"'
)
saml_response = extract_html_value(
self.saml_response_html, r'name="SAMLResponse" value="([^"]+)"'
)
self.session.post(consume_url, data={
'RelayState': relay_state,
'SAMLResponse': saml_response
})
self.session.post(
consume_url, data={"RelayState": relay_state, "SAMLResponse": saml_response}
)
self.session.get(f"{ANNY_BASE_URL}/en-us/login?target=/en-us/home?withoutIntent=true")
self.session.get(
f"{ANNY_BASE_URL}/en-us/login?target=/en-us/home?withoutIntent=true"
)