Skip to content

Commit

Permalink
Speed up oauth login
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanhed committed Jan 5, 2024
1 parent ec14395 commit 46b8ead
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/mijnbib/login_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ def __init__(self, username, password, url: str, br: mechanize.Browser):
def login(self) -> mechanize.Browser:
self._log_in()

url = self._base_url + "/mijn-bibliotheek/lidmaatschappen"
response = self._s.get(f"{url}", allow_redirects=False)
html = response.text if response is not None else ""
self._validate_logged_in(html)
# url = self._base_url + "/mijn-bibliotheek/lidmaatschappen"
# response = self._s.get(f"{url}", allow_redirects=False)
# html = response.text if response is not None else ""
# self._validate_logged_in(html)

# Transfer cookies from requests session to mechanize browser
self._br.set_cookiejar(self._s.cookies)
Expand Down Expand Up @@ -188,10 +188,16 @@ def _log_in(self):
_log.debug(f"login (4) cookies : {response.cookies}")
# _log.debug(f"login (4) text : {response.text}")

# (5) Open a useful page to confirm we're properly logged in.
# The Location header (from above) refers to "mijn-bibliotheek/overzicht", but this page is slow to open.
# So don't go there. Go to lidmaatschappen instead.
# (moved to next step)
if ("mijn-bibliotheek/overzicht" not in response.headers.get("location", "")) and (
"mijn-bibliotheek/lidmaatschappen" not in response.headers.get("location", "")
):
_log.warning(
"Not clear if properly logged in. Was expecting "
"'mijn-bibliotheek/overzicht' or 'mijn-bibliotheek/lidmaatschappen' "
"in location header, but couldn't find it"
)

# We now consider us logged in

def _validate_logged_in(self, html: str):
_log.debug("Checking if login is successful ...")
Expand Down

0 comments on commit 46b8ead

Please sign in to comment.