Skip to content

Auto-detect Life360 auth_token from Next.js assets - #7

Open
AndrewAubury wants to merge 1 commit into
vdbg:mainfrom
AndrewAubury:main
Open

Auto-detect Life360 auth_token from Next.js assets#7
AndrewAubury wants to merge 1 commit into
vdbg:mainfrom
AndrewAubury:main

Conversation

@AndrewAubury

Copy link
Copy Markdown
Contributor

This PR adds automatic detection of the Life360 auth_token (Basic Authorization token) by scraping the public login page and scanning the loaded Next.js chunk assets.

Background

Life360 periodically rotates the static Basic authentication token used when requesting OAuth access tokens. Previously this token had to be manually updated in the configuration, which could cause the integration to break whenever Life360 changed it.

Changes

  • Added findBasicAuth() method to dynamically locate the basicToken value from Life360's frontend assets.
  • The login page (/en-gb/login) is fetched and all referenced /_next/static/chunks/*.js files are scanned.
  • The script searches these files for the basicToken value and extracts it automatically.
  • When auth_token = "detect" is set in the config, the script will attempt to discover the correct token before authenticating.

Config Updates

The configuration now supports automatic detection:

auth_token = "detect"

If detection fails, the script will raise an exception to prevent silent authentication failures.

Benefits

  • Removes the need to manually update the Life360 Basic auth token.
  • Makes the integration resilient to frontend token rotations.
  • Keeps compatibility with manual token configuration if desired.

Notes

The detection works by parsing publicly available frontend assets and does not rely on undocumented API endpoints.

Comment thread life360.py
if token:
self.auth_token = token
return True
else:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need for else after a return statement

Comment thread life360.py
if self.auth_token == "detect":
logging.debug(f"Detecting Basic auth from Life360 assets.")
if not self.findBasicAuth():
logging.exception(f"Unable to detect basic auth.")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just raise an exception with the proper error msg vs. logging + raise?

Comment thread life360.py
if self.access_token and not force:
return

if self.auth_token == "detect":

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a few drawbacks as currently implemented:

  1. we need to do web scrapping each time we need to auth
  2. web scrapping is fragile; if life360 changes the page layout then it will fail
  3. when it does fail we no longer have the token documented in conf, even if if didn't change

Proposal:

  1. keep the hardcoded token in conf
  2. if it fails, do web scrapping
  3. if web scrapping succeeds, test the new token
  4. if the new token works, log a warning saying we're using a different token
  5. optional because hard to implement: ideally we'd want to preserve this new token. Problem is that it's probably hard to keep track of where the one we had before came from (template conf vs. actual conf vs. env var). So maybe preserve the new token in a text file collocated with app.py. Then step 2 would change into: check if that file exist and has a valid token before doing web scrapping

@AndrewAubury

Copy link
Copy Markdown
Contributor Author

Thank you for the review. Ill update the PR tomorrow with the suggested changed and maybe attempt the optional step. Python it not my normal go to language of choice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants