improved satbility on session expiration
This commit is contained in:
+10
-5
@@ -8,11 +8,13 @@ import string
|
||||
BASE_URL = 'https://emea.bff.cariad.digital/vehicle/v1'
|
||||
LOGIN_URL= 'https://emea.bff.cariad.digital/user-login/v1'
|
||||
|
||||
|
||||
def generate_url():
|
||||
nonce = ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=16))
|
||||
|
||||
return LOGIN_URL + '/authorize?nonce=' + nonce + '&redirect_uri=weconnect://authenticated'
|
||||
|
||||
|
||||
class WeConnectId:
|
||||
def __init__(self, email_address, password, access_token=None):
|
||||
self._email_address = email_address
|
||||
@@ -59,8 +61,7 @@ class WeConnectId:
|
||||
'password': self._password,
|
||||
}
|
||||
|
||||
access_token = None
|
||||
|
||||
self._access_token = None
|
||||
try:
|
||||
r = self._session.post(
|
||||
'https://identity.vwgroup.io/signin-service/v1/' + some_data['clientLegalEntityModel']['clientId'] + '/login/authenticate',
|
||||
@@ -71,6 +72,8 @@ class WeConnectId:
|
||||
# We expect a redirect to 'weconnect://authenticated', which requests doesn't understand
|
||||
self._access_token = re.search('access_token=([^&$]+)', str(e)).group(1)
|
||||
|
||||
print(f"AccessToken: {self._access_token}")
|
||||
|
||||
self._session.headers.update({
|
||||
'Authorization': 'Bearer ' + self._access_token,
|
||||
})
|
||||
@@ -81,9 +84,11 @@ class WeConnectId:
|
||||
def get(self, endpoint):
|
||||
r = self._session.get(BASE_URL + endpoint)
|
||||
|
||||
if r.status_code == 401:
|
||||
if r.status_code == 400 or r.status_code == 401:
|
||||
print(f"Error: {r.status_code}:{r.text}")
|
||||
print(f"Restart session")
|
||||
self._setup_session()
|
||||
self._sign_in(True)
|
||||
|
||||
r = self._session.get(BASE_URL + endpoint)
|
||||
return self.get(endpoint)
|
||||
|
||||
return r.json()
|
||||
|
||||
Reference in New Issue
Block a user