Add Tesla FleetAPI OAuth web login flow#642
Open
ngardiner wants to merge 15 commits into
Open
Conversation
Test Results 8 files ± 0 8 suites ±0 13m 24s ⏱️ -1s 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. |
…xposing TWCManager
…lient-secret flow; use Tesla Authorization Code grant-type wording
…plicit in docs, config and login UI
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.
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
auth.tesla.com/oauth2/v3/authorizewithresponse_type=code,client_id,redirect_uri,scope,state, andaudience(the regional FleetAPI base URL).authorization_codePOST tofleet-auth.prd.vn.cloud.tesla.com/oauth2/v3/tokenwithclient_id+client_secret+code+audience+redirect_uri.https://<host>/teslaAccount/callback; Tesla returns the browser to TWCManager and login completes with no copy/paste.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/regionAudiencehelpers.HTTPControl.py:/teslaAccount/login,/teslaAccount/callback,POST /teslaAccount/saveToken,teslaLogintemplate global, cheap token-basedapiAvailable(no live API call).teslaApiClientSecret,teslaApiRedirectUri,teslaApiRegion,teslaApiScope.docs/modules/Vehicle_TeslaAPI.md; README pointer; CHANGELOG entry.Config
Set
teslaApiClientID,teslaApiClientSecret,teslaApiRedirectUri(+ optionalteslaApiRegion/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_twcslavestill pass.