Auto-detect Life360 auth_token from Next.js assets - #7
Open
AndrewAubury wants to merge 1 commit into
Open
Conversation
vdbg
requested changes
Mar 5, 2026
| if token: | ||
| self.auth_token = token | ||
| return True | ||
| else: |
Owner
There was a problem hiding this comment.
nit: no need for else after a return statement
| 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.") |
Owner
There was a problem hiding this comment.
can we just raise an exception with the proper error msg vs. logging + raise?
| if self.access_token and not force: | ||
| return | ||
|
|
||
| if self.auth_token == "detect": |
Owner
There was a problem hiding this comment.
There's a few drawbacks as currently implemented:
- we need to do web scrapping each time we need to auth
- web scrapping is fragile; if life360 changes the page layout then it will fail
- when it does fail we no longer have the token documented in conf, even if if didn't change
Proposal:
- keep the hardcoded token in conf
- if it fails, do web scrapping
- if web scrapping succeeds, test the new token
- if the new token works, log a warning saying we're using a different token
- 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
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
findBasicAuth()method to dynamically locate thebasicTokenvalue from Life360's frontend assets./en-gb/login) is fetched and all referenced/_next/static/chunks/*.jsfiles are scanned.basicTokenvalue and extracts it automatically.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:
If detection fails, the script will raise an exception to prevent silent authentication failures.
Benefits
Notes
The detection works by parsing publicly available frontend assets and does not rely on undocumented API endpoints.