Skip to content

Commit

Permalink
Merge pull request #138 from Cogito/edge-cookies
Browse files Browse the repository at this point in the history
Add support for retrieving session cookies from the Edge browser
  • Loading branch information
wimglenn authored Jan 7, 2024
2 parents 9a0a72f + 2c86f82 commit bd6826e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ variable to some existing directory if you wish to use another location to store

*New in version 0.9.0.* There's a utility script ``aocd-token`` which attempts to
find session tokens from your browser's cookie storage. This feature is experimental
and requires you to additionally install the package ``browser-cookie3``. Only Chrome
and Firefox browsers are currently supported. On macOS, you may get an authentication
and requires you to additionally install the package ``browser-cookie3``. Only Chrome,
Firefox, and Edge browsers are currently supported. On macOS, you may get an authentication
dialog requesting permission, since Python is attempting to read browser storage files.
This is expected, the script *is* actually scraping those private files to access AoC
session token(s).
Expand Down
14 changes: 12 additions & 2 deletions aocd/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@ def get_working_tokens() -> dict[str, str]:
firefox = [c for c in firefox if c.name == "session"]
log.info("%d candidates from firefox", len(firefox))

log.info("checking edge cookie jar...")
try:
edge = bc3.edge(domain_name=".adventofcode.com")
except Exception as err:
log.debug("Couldn't scrape edge - %s: %s", type(err), err)
edge = []
else:
edge = [c for c in edge if c.name == "session"]
log.info("%d candidates from edge", len(edge))

# order preserving de-dupe
tokens = list({}.fromkeys([c.value for c in chrome + firefox]))
removed = len(chrome + firefox) - len(tokens)
tokens = list({}.fromkeys([c.value for c in chrome + firefox + edge]))
removed = len(chrome + firefox + edge) - len(tokens)
if removed:
log.info("Removed %d duplicate%s", removed, "s"[: removed - 1])

Expand Down

0 comments on commit bd6826e

Please sign in to comment.