Skip to content

Commit

Permalink
Use proxy client_id for token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
RichieB2B committed Jan 20, 2024
1 parent cce56df commit 4b9fa1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions etc/twcmanager/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@
#
# Only set "httpProxyCert" when setting "teslaApiUrl" to a local proxy.
#"httpProxyCert": "/path/to/public_key.pem",
#
# Only set "teslaApiClientID" when setting "teslaApiUrl" to a local proxy.
#"teslaApiClientID": "client-id-of-proxy",

# The cloudUpdateInterval determines how often to poll certain
# data retrieved from the Tesla API to evaluate policy.
Expand Down
5 changes: 3 additions & 2 deletions lib/TWCManager/Vehicle/TeslaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class TeslaAPI:
__authURL = "https://auth.tesla.com/oauth2/v3/token"
__callbackURL = "https://auth.tesla.com/void/callback"
baseURL = "https://owner-api.teslamotors.com/api/1/vehicles"
refreshClientID = "ownerapi"
proxyCert = None
carApiLastErrorTime = 0
carApiBearerToken = ""
Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(self, master):
try:
self.config = master.config
self.baseURL = self.config["config"].get("teslaApiUrl", "https://owner-api.teslamotors.com/api/1/vehicles")
self.refreshClientID = self.config["config"].get("teslaApiClientID", "ownerapi")
self.proxyCert = self.config["config"].get("httpProxyCert", None)
self.minChargeLevel = self.config["config"].get("minChargeLevel", -1)
self.chargeUpdateInterval = self.config["config"].get(
Expand Down Expand Up @@ -108,10 +110,9 @@ def apiRefresh(self):
# days when first issued, so we'll get a new token every 15 days.
headers = {"accept": "application/json", "Content-Type": "application/json"}
data = {
"client_id": "ownerapi",
"client_id": self.refreshClientID,
"grant_type": "refresh_token",
"refresh_token": self.getCarApiRefreshToken(),
"scope": "openid email offline_access",
}
req = None
now = time.time()
Expand Down

0 comments on commit 4b9fa1e

Please sign in to comment.