Fix web login: migrate to /api/v2/auth/web/login + push approval (closes #250)#355
Open
twannooitmeer wants to merge 1 commit into
Open
Fix web login: migrate to /api/v2/auth/web/login + push approval (closes #250)#355twannooitmeer wants to merge 1 commit into
twannooitmeer wants to merge 1 commit into
Conversation
Trade Republic deprecated the legacy /api/v1/auth/web/login endpoint
(all requests now return HTTP 426 CLIENT_VERSION_OUTDATED regardless of
User-Agent). The current web app uses /api/v2/auth/web/login with:
* x-tr-platform: web
* x-tr-app-version: 15.7.0 (web track, distinct from the Android version)
* x-tr-device-info: base64(JSON) browser fingerprint
* x-aws-waf-token: same value as the aws-waf-token cookie
The v2 flow also no longer issues a numeric code: the user approves the
login via a push notification in the TR mobile app. The web app polls
GET /api/v2/auth/web/login/processes/{processId} until the push is
acknowledged.
Changes:
* pytr/api.py: add TR_WEB_APP_VERSION / TR_WEB_USER_AGENT / TR_WEB_LOGIN_PATH
constants (overridable via env), _get_device_id() persisting a stable
UUID at ~/.pytr/device_id, _build_device_info_header(), _auth_headers()
helper, and await_web_login_approval() polling loop.
* initiate_weblogin() now POSTs to v2 with the new headers, polls for
push approval, and returns 0 to signal the v2 flow.
* complete_weblogin('') is a no-op for v2 (approval already happened).
* pytr/account.py: when initiate_weblogin() returns 0, skip the
code/SMS prompts and call complete_weblogin('') directly.
Refs: pytr-org#250
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.
Summary
Trade Republic deprecated the legacy
/api/v1/auth/web/loginendpoint. All requests to it currently returnHTTP 426 CLIENT_VERSION_OUTDATEDregardless ofUser-Agent, which makespytr loginunusable on a fresh install (refs #250). (Verified on 2026-05-29; the cutover itself happened at some earlier point.)This PR migrates the auth flow to
/api/v2/auth/web/login, which is whatapp.traderepublic.comcurrently uses.What changed
/api/v2/auth/web/loginrequires four new headersCaptured from the live web app:
The
x-tr-device-infopayload looks like:{ "stableDeviceId": "<64 hex chars>", "model": "Apple Macintosh", "browser": "Chrome", "browserVersion": "148.0.0.0", "os": "Mac OS", "osVersion": "10.15.7", "timezone": "Europe/Amsterdam", "timezoneOffset": -120, "screen": "1800x1169x30", "preferredLanguages": ["en", "en-US"], "numberOfCores": 12, "deviceMemory": 16 }v2 uses push-approval, not a numeric code
The v2 flow no longer issues an SMS/numeric code. Instead the user approves the login via a push notification in the Trade Republic mobile app, and the web client polls
GET /api/v2/auth/web/login/processes/{processId}until the responsestatusindicates approval (and atr_sessioncookie is set).Implementation
pytr/api.pyTR_WEB_APP_VERSION,TR_WEB_USER_AGENT,TR_WEB_LOGIN_PATH, overridable viaPYTR_TR_APP_VERSION/PYTR_TR_USER_AGENTso future TR bumps don't require a code change:_get_device_id()persists a stable 64-hex device id at~/.pytr/device_id._build_device_info_header()constructs the base64-encoded JSON fingerprint._auth_headers()returns all four required headers (WAF token included when known).await_web_login_approval()polls the newprocesses/{processId}endpoint every 2 s with a 180 s timeout. Detects approval via either an explicitstatusfield or the presence of atr_sessioncookie.initiate_weblogin()now POSTs to v2 with the new headers, kicks off the poll, and returns0to signal the v2 flow.complete_weblogin('')is a no-op (approval already happened during initiation).pytr/account.pyinitiate_weblogin()returns0, skip the code/SMS prompts entirely and callcomplete_weblogin('')to persist cookies.countdown > 0case (dead branch in practice, but safe to keep).Tested
Verified locally end-to-end on macOS, Python 3.12: WAF token fetch →
processId→ push approval → session cookie →Logged in.Notes
trustDeviceRegistrationOptions(returned by the process endpoint); that would let users skip the push step on subsequent logins. Happy to follow up in a separate PR.