access_token = ""
refresh_token = ""
token_expires_in = ""
- oauth_url = URL_OAUTH
- res_url_prefix = URL_RES_PREFIX
########################
# Init
# Check Token
########################
def CheckToken(self, token):
+ if token == None:
+ _LOGGER.error ("Error reading token.")
+ return False
if "error" in token:
if "error_description" in token:
_LOGGER.error ("Error retriving token: " + token["error_description"])
# Create Token
########################
def CreateToken(self):
+
+ auth_url = (
+ f"{URL_OAUTH_AUTH}&" +
+ f"client_id={self.client_id}&" +
+ f"redirect_uri={REDIRECT_URL}&" +
+ f"scope={SCOPE}"
+ )
+
print( "Open the browser and insert this link:\n" )
- print( "https://id.mercedes-benz.com/as/authorization.oauth2?response_type=code&client_id=" + self.client_id + "&redirect_uri=" + REDIRECT_URL + "&scope=" + SCOPE + "\n")
+ print(auth_url + "\n")
print( "Copy the code in the url:")
auth_code = input()
RESOURCES_FILE = ".mercedesme_resources"
REDIRECT_URL = "https://localhost"
SCOPE = "mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20offline_access"
-URL_OAUTH = "https://id.mercedes-benz.com/as/token.oauth2"
+URL_OAUTH_BASE = "https://id.mercedes-benz.com/as"
+URL_OAUTH_AUTH = URL_OAUTH_BASE + "/authorization.oauth2?response_type=code"
+URL_OAUTH_TOKEN = URL_OAUTH_BASE + "/token.oauth2"
URL_RES_PREFIX = "https://api.mercedes-benz.com/vehicledata/v2"
# File Parameters
access_token = ""
refresh_token = ""
token_expires_in = ""
- oauth_url = URL_OAUTH
- res_url_prefix = URL_RES_PREFIX
########################
# Init
# Check Token
########################
def CheckToken(self, token):
+ if token == None:
+ _LOGGER.error ("Error reading token.")
+ return False
if "error" in token:
if "error_description" in token:
_LOGGER.error ("Error retriving token: " + token["error_description"])
# Create Token
########################
def CreateToken(self):
+
+ auth_url = (
+ f"{URL_OAUTH_AUTH}&" +
+ f"client_id={self.client_id}&" +
+ f"redirect_uri={REDIRECT_URL}&" +
+ f"scope={SCOPE}"
+ )
+
print( "Open the browser and insert this link:\n" )
- print( "https://id.mercedes-benz.com/as/authorization.oauth2?response_type=code&client_id=" + self.client_id + "&redirect_uri=" + REDIRECT_URL + "&scope=" + SCOPE + "\n")
+ print(auth_url + "\n")
print( "Copy the code in the url:")
auth_code = input()
RESOURCES_FILE = ".mercedesme_resources"
REDIRECT_URL = "https://localhost"
SCOPE = "mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20offline_access"
-URL_OAUTH = "https://id.mercedes-benz.com/as/token.oauth2"
+URL_OAUTH_BASE = "https://id.mercedes-benz.com/as"
+URL_OAUTH_AUTH = URL_OAUTH_BASE + "/authorization.oauth2?response_type=code"
+URL_OAUTH_TOKEN = URL_OAUTH_BASE + "/token.oauth2"
URL_RES_PREFIX = "https://api.mercedes-benz.com/vehicledata/v2"
#UPDATE_SIGNAL = "mercedesmeapi_update"
# Refresh
data = "grant_type=refresh_token&refresh_token=" + config.refresh_token
- res = requests.post(URL_OAUTH, data = data, headers = headers)
+ res = requests.post(URL_OAUTH_TOKEN, data = data, headers = headers)
try:
token = res.json()
except ValueError:
# Refresh
data = "grant_type=refresh_token&refresh_token=" + config.refresh_token
- res = requests.post(URL_OAUTH, data = data, headers = headers)
+ res = requests.post(URL_OAUTH_TOKEN, data = data, headers = headers)
try:
token = res.json()
except ValueError: