Skip to content

Add Tesla FleetAPI OAuth web login flow#642

Open
ngardiner wants to merge 15 commits into
mainfrom
feature/fleet-oauth-login
Open

Add Tesla FleetAPI OAuth web login flow#642
ngardiner wants to merge 15 commits into
mainfrom
feature/fleet-oauth-login

Conversation

@ngardiner

Copy link
Copy Markdown
Owner

Restores a guided in-UI Tesla login, now FleetAPI-correct, following the Owner API removal in #640. Without this, cloud tokens can only be hand-pasted, synced from TeslaMate, or skipped via BLE.

Flow

  • Authorize (browser): auth.tesla.com/oauth2/v3/authorize with response_type=code, client_id, redirect_uri, scope, state, and audience (the regional FleetAPI base URL).
  • Token exchange (server): form-encoded authorization_code POST to fleet-auth.prd.vn.cloud.tesla.com/oauth2/v3/token with client_id + client_secret + code + audience + redirect_uri.
  • Two callback options, same exchange code:
    • Auto-capture: register https://<host>/teslaAccount/callback; Tesla returns the browser to TWCManager and login completes with no copy/paste.
    • Paste-back: copy the redirect URL and paste it into the web UI (works for LAN-only installs).
  • Refresh path was already FleetAPI-correct (client_id + refresh_token, rotates the refresh token); unchanged.

Changes

  • TeslaAPI.py: getLoginURL, fleetTokenExchange (state validation, form-encoded exchange, token storage), saveApiToken (paste parser), teslaLoginInfo/regionAudience helpers.
  • HTTPControl.py: /teslaAccount/login, /teslaAccount/callback, POST /teslaAccount/saveToken, teslaLogin template global, cheap token-based apiAvailable (no live API call).
  • Web UI: config-aware Fleet login templates (region picker, login link, paste box), re-included in both themes.
  • New config fields: teslaApiClientSecret, teslaApiRedirectUri, teslaApiRegion, teslaApiScope.
  • New setup guide docs/modules/Vehicle_TeslaAPI.md; README pointer; CHANGELOG entry.

Config

Set teslaApiClientID, teslaApiClientSecret, teslaApiRedirectUri (+ optional teslaApiRegion/teslaApiScope) in config.json. Registering a developer.tesla.com app and the Vehicle Command proxy / partner registration remain external prerequisites (documented, not automated).

Tests

8 unit tests (requests-mock): authorize URL construction, region audience, state-mismatch rejection, successful exchange asserting client_secret/audience/grant_type, Tesla error passthrough, paste-back. test_httpcontrol/test_vehicle_priority/test_twcslave still pass.

@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown

Test Results

    8 files  ± 0      8 suites  ±0   13m 24s ⏱️ -1s
  651 tests +10    593 ✅ +10  2 💤 ±0   43 ❌ ±0  13 🔥 ±0 
2 604 runs  +40  2 372 ✅ +40  8 💤 ±0  172 ❌ ±0  52 🔥 ±0 

For more details on these failures and errors, see this check.

Results for commit 622c471. ± Comparison against base commit 0b1ed3a.

♻️ This comment has been updated with latest results.

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.

1 participant