-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,9 @@ TeslaPy 2.0.0+ no longer implements headless authentication. The constructor dif | |
| `cache_loader` | (optional) function that returns the cache dict | | ||
| `cache_dumper` | (optional) function with one argument, the cache dict | | ||
| `sso_base_url` | (optional) URL of SSO service, set to `https://auth.tesla.cn/` if your email is registered in another region | | ||
| `state` | (optional) state string for CSRF protection | | ||
| `code_verifier` | (optional) PKCE code verifier string | | ||
| `app_user_agent` | (optional) X-Tesla-User-Agent string | | ||
|
||
TeslaPy 2.1.0+ no longer implements [RFC 7523](https://tools.ietf.org/html/rfc7523) and uses the SSO token for all API requests. | ||
|
||
|
@@ -43,9 +46,11 @@ The convenience method `api()` uses named endpoints listed in *endpoints.json* t | |
| Call | Description | | ||
| --- | --- | | ||
| `request()` | performs API call using relative or absolute URL, serialization and error message handling | | ||
| `authorization_url()` | forms authorization URL with [PKCE](https://oauth.net/2/pkce/) extension | | ||
| `new_code_verifier()` | generates code verifier for [PKCE](https://oauth.net/2/pkce/) | | ||
| `authorization_url()` | forms authorization URL with [PKCE](https://oauth.net/2/pkce/) extension and tries to detect the accounts registered region | | ||
| `fetch_token()` | requests an SSO token using Authorization Code grant with [PKCE](https://oauth.net/2/pkce/) extension | | ||
| `refresh_token()` | requests an SSO token using [Refresh Token](https://oauth.net/2/grant-types/refresh-token/) grant | | ||
| `close()` | remove all requests adapter instances | | ||
| `logout()` | removes token from cache, returns logout URL and optionally signs out using system's default web browser | | ||
| `vehicle_list()` | returns a list of Vehicle objects | | ||
| `battery_list()` | returns a list of Battery objects | | ||
|
@@ -189,6 +194,29 @@ print(vehicles[0]) | |
tesla.close() | ||
``` | ||
|
||
#### Alternative staged | ||
|
||
Support for staged authorization has been added to TeslaPy 2.5.0. The keyword arguments `state` and `code_verifier` are accepted by the `Tesla` class constructor, the `authorization_url()` method and the `fetch_token()` method. | ||
|
||
```python | ||
import teslapy | ||
# First stage | ||
tesla = teslapy.Tesla('[email protected]') | ||
if not tesla.authorized: | ||
state = tesla.new_state() | ||
code_verifier = tesla.new_code_verifier() | ||
print('Use browser to login. Page Not Found will be shown at success.') | ||
print('Open: ' + tesla.authorization_url(state=state, code_verifier=code_verifier)) | ||
tesla.close() | ||
# Second stage | ||
tesla = teslapy.Tesla('[email protected]', state=state, code_verifier=code_verifier) | ||
if not tesla.authorized: | ||
tesla.fetch_token(authorization_response=input('Enter URL after authentication: ')) | ||
vehicles = tesla.vehicle_list() | ||
print(vehicles[0]) | ||
tesla.close() | ||
``` | ||
|
||
#### 3rd party authentication apps | ||
|
||
TeslaPy 2.4.0+ supports usage of a refresh token obtained by 3rd party [authentication apps](https://teslascope.com/help/generating-tokens). The refresh token is used to obtain an access token and both are cached for persistence, so you only need to supply the refresh token only once. | ||
|
This file contains 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