From c4a6fd470dfbdb430c66ad51025e18a52c479c33 Mon Sep 17 00:00:00 2001 From: Brandon McFarlin <6525520+Brandawg93@users.noreply.github.com> Date: Mon, 20 Jun 2022 18:51:00 -0400 Subject: [PATCH] fix connection --- src/fordpass-connection.ts | 26 ++++++++++++++++---------- src/fordpass.ts | 22 ++++++++++++---------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/fordpass-connection.ts b/src/fordpass-connection.ts index 8da3117..43543fa 100644 --- a/src/fordpass-connection.ts +++ b/src/fordpass-connection.ts @@ -8,7 +8,13 @@ const authUrl = 'https://sso.ci.ford.com/'; const vehiclesUrl = 'https://services.cx.ford.com/api/dashboard/v1/users/vehicles'; const defaultAppId = '71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592'; const clientId = '9fb503e0-715b-47e8-adfd-ad4b7770f73b'; -const userAgent = 'FordPass/5 CFNetwork/1325.0.1 Darwin/21.1.0'; +const userAgent = 'FordPass/5 CFNetwork/1333.0.4 Darwin/21.5.0'; + +const headers = { + 'User-Agent': userAgent, + 'Accept-Language': 'en-US,en;q=0.9', + 'Accept-Encoding': 'gzip, deflate, br', +}; export class Connection { private config: FordpassConfig; @@ -28,7 +34,7 @@ export class Connection { url: url, headers: { 'Content-Type': 'application/x-www-form-urlencoded', - 'User-Agent': userAgent, + ...headers, }, data: querystring.stringify({ client_id: clientId, @@ -41,16 +47,16 @@ export class Connection { try { const result = await axios(options); if (result.status === 200 && result.data.access_token) { - const nextResult = await axios.put( - 'https://api.mps.ford.com/api/oauth2/v1/token', + const nextResult = await axios.post( + 'https://api.mps.ford.com/api/token/v2/cat-with-ci-access-token', { - code: result.data.access_token, + ciToken: result.data.access_token, }, { headers: { 'Content-Type': 'application/json', - 'User-Agent': userAgent, 'Application-Id': this.applicationId, + ...headers, }, }, ); @@ -74,16 +80,16 @@ export class Connection { async refreshAuth(): Promise { try { if (this.config.refresh_token) { - const result = await axios.put( - 'https://api.mps.ford.com/api/oauth2/v1/refresh', + const result = await axios.post( + 'https://api.mps.ford.com/api/token/v2/cat-with-refresh-token', { refresh_token: this.config.refresh_token, }, { headers: { 'Content-Type': 'application/json', - 'User-Agent': userAgent, 'Application-Id': this.applicationId, + ...headers, }, }, ); @@ -113,9 +119,9 @@ export class Connection { url: vehiclesUrl, headers: { 'Content-Type': 'application/json', - 'User-Agent': userAgent, 'Auth-Token': this.config.access_token, 'Application-Id': this.applicationId, + ...headers, }, }; diff --git a/src/fordpass.ts b/src/fordpass.ts index a34ee0d..dc4670e 100644 --- a/src/fordpass.ts +++ b/src/fordpass.ts @@ -7,7 +7,7 @@ import { FordpassConfig } from './types/config'; const defaultHeaders = { 'Content-Type': 'application/json', - 'User-Agent': 'FordPass/5 CFNetwork/1325.0.1 Darwin/21.1.0', + 'User-Agent': 'FordPass/5 CFNetwork/1333.0.4 Darwin/21.5.0', }; const fordAPIUrl = 'https://usapi.cv.ford.com/'; @@ -48,7 +48,7 @@ export class Vehicle { } } - const url = fordAPIUrl + `/api/vehicles/v4/${this.vin}/status`; + const url = fordAPIUrl + `/api/vehicles/v5/${this.vin}/status`; const options: AxiosRequestConfig = { url: url, headers: defaultHeaders, @@ -87,27 +87,27 @@ export class Vehicle { switch (command) { case Command.START: { method = 'PUT'; - endpoint = `api/vehicles/v2/${this.vin}/engine/start`; + endpoint = `api/vehicles/v5/${this.vin}/engine/start`; break; } case Command.STOP: { method = 'DELETE'; - endpoint = `api/vehicles/v2/${this.vin}/engine/start`; + endpoint = `api/vehicles/v5/${this.vin}/engine/start`; break; } case Command.LOCK: { method = 'PUT'; - endpoint = `api/vehicles/v2/${this.vin}/doors/lock`; + endpoint = `api/vehicles/v5/${this.vin}/doors/lock`; break; } case Command.UNLOCK: { method = 'DELETE'; - endpoint = `api/vehicles/v2/${this.vin}/doors/lock`; + endpoint = `api/vehicles/v5/${this.vin}/doors/lock`; break; } case Command.REFRESH: { method = 'PUT'; - endpoint = `api/vehicles/v2/${this.vin}/status`; + endpoint = `api/vehicles/v5/${this.vin}/status`; break; } default: { @@ -144,11 +144,13 @@ export class Vehicle { } let endpoint = ''; if (command === Command.START || command === Command.STOP) { - endpoint = `api/vehicles/v2/${this.vin}/engine/start/${commandId}`; + endpoint = `api/vehicles/v5/${this.vin}/engine/start/${commandId}`; } else if (command === Command.LOCK || command === Command.UNLOCK) { - endpoint = `api/vehicles/v2/${this.vin}/doors/lock/${commandId}`; + endpoint = `api/vehicles/v5/${this.vin}/doors/lock/${commandId}`; } else if (command === Command.REFRESH) { - endpoint = `api/vehicles/v2/${this.vin}/status/${commandId}`; + endpoint = `api/vehicles/v5/${this.vin}/status/${commandId}`; + } else if (command === Command.PANIC) { + endpoint = `api/vehicles/v5/${this.vin}/panic/${commandId}`; } else { this.log.error('invalid command'); }