fix compatibility with other realm

This commit is contained in:
Florian Bezannier
2020-11-26 12:27:43 +01:00
parent 53a5cecb84
commit 7c303b1014
2 changed files with 12 additions and 9 deletions
+10 -7
View File
@@ -15,11 +15,15 @@ from psa_connectedcar import ApiClient
from psa_connectedcar.rest import ApiException
from MyLogger import logger
oauhth_url = "https://idpcvs.peugeot.com/am/oauth2/access_token"
oauhth_url = {"clientsB2CPeugeot":"https://idpcvs.peugeot.com/am/oauth2/access_token",
"clientsB2CCitroen":"https://idpcvs.citroen.com/am/oauth2/access_token",
"clientsB2CDS": "https://idpcvs.driveds.com/am/oauth2/access_token",
"clientsB2COpel":"https://idpcvs.opel.com/am/oauth2/access_token",
"clientsB2CVauxhall":"https://idpcvs.vauxhall.co.uk/am/oauth2/access_token"}
authorize_service = "https://api.mpsa.com/api/connectedcar/v2/oauth/authorize"
remote_url = "https://api.groupe-psa.com/connectedcar/v4/virtualkey/remoteaccess/token?client_id="
scopes = ['openid profile']
realm = "clientsB2CPeugeot"
MQTT_SERVER = "mwa.mpsa.com"
class OpenIdCredentialManager(CredentialManager):
@@ -95,12 +99,12 @@ class MyPSACC:
def connect(self, user, password):
self.manager.init_with_user_credentials(user, password, realm)
self.manager.init_with_user_credentials(user, password, self.realm)
def __init__(self, refresh_token, client_id, client_secret, remote_refresh_token, customer_id, proxies=None,
realm=realm):
def __init__(self, refresh_token, client_id, client_secret, remote_refresh_token, customer_id, realm, proxies=None):
self.realm = realm
self.service_information = ServiceInformation(authorize_service,
oauhth_url,
oauhth_url[self.realm],
client_id,
client_secret,
scopes, False)
@@ -115,7 +119,6 @@ class MyPSACC:
self.setProxies(proxies)
self.customer_id = customer_id
self._confighash = None
self.realm = realm
self.api_config.verify_ssl = False
self.api_config.api_key['client_id'] = self.client_id
self.api_config.api_key['x-introspect-realm'] = self.realm
+2 -2
View File
@@ -61,9 +61,9 @@ else:
try:
if "refresh_token" in remote_dec:
remote_refresh_token = remote_dec["refresh_token"]
# Mypeugeot >= 1.26
else:
remote_refresh_token = next(iter(remote_dec.values()))["refresh_token"]
# Mypeugeot >= 1.26
except:
traceback.print_exc()
print(remote_dec)
@@ -72,7 +72,7 @@ else:
client_email = input("mypeugeot email: ")
client_paswword = input("mypeugeot password: ")
client_realm = input("What is the car api realm : clientsB2CPeugeot, clientsB2CDS, clientsB2COpel, clientsB2CVauxhall\n")
client_realm = input("What is the car api realm : clientsB2CPeugeot, clientsB2CCitroen, clientsB2CDS, clientsB2COpel, clientsB2CVauxhall\n")
psacc = MyPSACC(None, client_id, client_secret, remote_refresh_token, customer_id, realm=client_realm)
psacc.connect(client_email, client_paswword)