Skip to content

Commit

Permalink
Merge pull request #492 from itchannel/1.68
Browse files Browse the repository at this point in the history
1.68
  • Loading branch information
itchannel authored May 9, 2024
2 parents 52c1a57 + 9bce51c commit ba3e989
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
25 changes: 25 additions & 0 deletions custom_components/fordpass/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,28 @@
"ignition": {"icon": "hass:power"},
# "guardmode": {"icon": "mdi:shield-key"}
}

REGIONS = {
"UK&Europe": {
"region": "1E8C7794-FF5F-49BC-9596-A1E0C86C5B19",
"locale": "EN-IE",
"locale_short": "IE", #Temp fix
"locale_url": "https://login.ford.ie"
},
"Australia": {
"region": "5C80A6BB-CF0D-4A30-BDBF-FC804B5C1A98",
"locale": "EN-AU",
"locale_short": "AUS",
"locale_url": "https://login.ford.com.au"
},
"North America & Canada": {
"region": "71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592",
"locale": "EN-AU",
"locale_short": "AUS",
"locale_url": "https://login.ford.com.au" #Temp fix until I can implement the correct American URL
}

}



39 changes: 12 additions & 27 deletions custom_components/fordpass/fordpass_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
from homeassistant import exceptions
from .const import REGIONS

_LOGGER = logging.getLogger(__name__)
defaultHeaders = {
Expand All @@ -34,23 +35,6 @@
"Content-Type": "application/json",
}

region_lookup = {
"UK&Europe": "1E8C7794-FF5F-49BC-9596-A1E0C86C5B19",
"Australia": "5C80A6BB-CF0D-4A30-BDBF-FC804B5C1A98",
"North America & Canada": "71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592",
}

locale_lookup = {
"UK&Europe": "EN-GB",
"Australia": "EN-AU",
"North America & Canada": "EN-US",
}

locale_short_lookup = {
"UK&Europe": "GB",
"Australia": "AUS",
"North America & Canada": "USA",
}


NEW_API = True
Expand All @@ -60,7 +44,7 @@
SSO_URL = "https://sso.ci.ford.com"
AUTONOMIC_URL = "https://api.autonomic.ai/v1"
AUTONOMIC_ACCOUNT_URL = "https://accounts.autonomic.ai/v1"
FORD_LOGIN_URL = "https://login.ford.com"
#FORD_LOGIN_URL = "https://login.ford.com"

session = requests.Session()

Expand All @@ -74,10 +58,11 @@ def __init__(
self.username = username
self.password = password
self.save_token = save_token
self.region = region_lookup[region]
self.country_code = locale_lookup[region]
self.short_code = locale_short_lookup[region]
self.region2 = region
self.region = REGIONS[region]["region"]
self.country_code = REGIONS[region]["locale"]
self.short_code = REGIONS[region]["locale_short"]
self.region2 = REGIONS[region]["region"]
self.ford_login_url = REGIONS[region]["locale_url"]
self.vin = vin
self.token = None
self.expires = None
Expand Down Expand Up @@ -115,7 +100,7 @@ def auth2_step1(self):
code1 = ''.join(random.choice(string.ascii_lowercase) for i in range(43))
code_verifier = self.generate_hash(code1)
step1_session = requests.session()
step1_url = f"{FORD_LOGIN_URL}/4566605f-43a7-400a-946e-89cc9fdb0bd7/B2C_1A_SignInSignUp_{self.country_code}/oauth2/v2.0/authorize?redirect_uri=fordapp://userauthorized&response_type=code&max_age=3600&scope=%2009852200-05fd-41f6-8c21-d36d3497dc64%20openid&client_id=09852200-05fd-41f6-8c21-d36d3497dc64&code_challenge={code_verifier}&code_challenge_method=S256&ui_locales={self.country_code}&language_code={self.country_code}&country_code={self.short_code}&ford_application_id=5C80A6BB-CF0D-4A30-BDBF-FC804B5C1A98"
step1_url = f"{self.ford_login_url}/4566605f-43a7-400a-946e-89cc9fdb0bd7/B2C_1A_SignInSignUp_{self.country_code}/oauth2/v2.0/authorize?redirect_uri=fordapp://userauthorized&response_type=code&max_age=3600&scope=%2009852200-05fd-41f6-8c21-d36d3497dc64%20openid&client_id=09852200-05fd-41f6-8c21-d36d3497dc64&code_challenge={code_verifier}&code_challenge_method=S256&ui_locales={self.country_code}&language_code={self.country_code}&country_code={self.short_code}&ford_application_id=5C80A6BB-CF0D-4A30-BDBF-FC804B5C1A98"

step1get = step1_session.get(
step1_url,
Expand Down Expand Up @@ -144,11 +129,11 @@ def auth2_step1(self):
"signInName": self.username,
"password": self.password,
}
urlp = f"{FORD_LOGIN_URL}/4566605f-43a7-400a-946e-89cc9fdb0bd7/B2C_1A_SignInSignUp_{self.country_code}/SelfAsserted?tx={transId}&p=B2C_1A_SignInSignUp_en-AU"
urlp = f"{self.ford_login_url}/4566605f-43a7-400a-946e-89cc9fdb0bd7/B2C_1A_SignInSignUp_{self.country_code}/SelfAsserted?tx={transId}&p=B2C_1A_SignInSignUp_{self.country_code}"
_LOGGER.debug(urlp)
headers = {
**loginHeaders,
"Origin": "https://login.ford.com",
"Origin": self.ford_login_url,
"Referer": step1_url,
"X-Csrf-Token": csrfToken
}
Expand All @@ -171,7 +156,7 @@ def auth2_step1(self):


step1pt2 = step1_session.get(
f"{FORD_LOGIN_URL}/4566605f-43a7-400a-946e-89cc9fdb0bd7/B2C_1A_SignInSignUp_{self.country_code}/api/CombinedSigninAndSignup/confirmed?rememberMe=false&csrf_token={csrfToken}",
f"{self.ford_login_url}/4566605f-43a7-400a-946e-89cc9fdb0bd7/B2C_1A_SignInSignUp_{self.country_code}/api/CombinedSigninAndSignup/confirmed?rememberMe=false&csrf_token={csrfToken}",
headers=headers,
allow_redirects=False,
)
Expand All @@ -194,7 +179,7 @@ def auth2_step1(self):
}

step1pt3 = step1_session.post(
f"{FORD_LOGIN_URL}/4566605f-43a7-400a-946e-89cc9fdb0bd7/B2C_1A_SignInSignUp_{self.country_code}/oauth2/v2.0/token",
f"{self.ford_login_url}/4566605f-43a7-400a-946e-89cc9fdb0bd7/B2C_1A_SignInSignUp_{self.country_code}/oauth2/v2.0/token",
headers=headers,
data=data
)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/fordpass/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"loggers": ["custom_components.fordpass"],
"requirements": [],
"ssdp": [],
"version": "0.1.66",
"version": "0.1.68",
"zeroconf": []
}
4 changes: 4 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## **Changelog**
### Version 1.68
- Fix for missing locale
### Version 1.67
- Temp fix for login issues (Uses different region login servers, may get blocked soon!)
### Version 1.66
- Remove deprecated GPS source type
- Added data_description translations
Expand Down

0 comments on commit ba3e989

Please sign in to comment.