Skip to content

Commit

Permalink
fix(login): Add an additional call to /authenticate to mimic smartmet…
Browse files Browse the repository at this point in the history
…er web portal changes

Fixes #281
  • Loading branch information
DarwinsBuddy committed Nov 29, 2024
1 parent 119ba21 commit a43ae09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions custom_components/wnsm/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ def credentials_login(self, url):
try:
result = self.session.post(
url,
data={
"username": self.username,
"login": " "
},
allow_redirects=False,
)
tree = html.fromstring(result.content)
action = tree.xpath("(//form/@action)")[0]

result = self.session.post(
action,
data={
"username": self.username,
"password": self.password,
Expand Down
6 changes: 6 additions & 0 deletions tests/it/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ def mock_authenticate(requests_mock: Mocker, username, password, code=RESPONSE_C
}
authenticate_url = f'https://log.wien/auth/realms/logwien/login-actions/authenticate?{parse.urlencode(authenticate_query_params)}'

# for some weird reason we have to perform this call before. maybe to create a login session. idk
requests_mock.post(authenticate_url, status_code=status,
additional_matcher=post_data_matcher({"username": username, "login": " "}),
text=files('test_resources').joinpath('auth.html').read_text()
)

if status == 302:
redirect_url = f'{REDIRECT_URI}/#state=cb142d1b-d8b4-4bf3-8a3e-92544790c5c4' \
'&session_state=949e0f0d-b447-4208-bfef-273d694dc633' \
Expand Down

0 comments on commit a43ae09

Please sign in to comment.