Skip to content

Commit

Permalink
fix connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandawg93 committed Jun 20, 2022
1 parent 45c0950 commit c4a6fd4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
26 changes: 16 additions & 10 deletions src/fordpass-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
},
},
);
Expand All @@ -74,16 +80,16 @@ export class Connection {
async refreshAuth(): Promise<any> {
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,
},
},
);
Expand Down Expand Up @@ -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,
},
};

Expand Down
22 changes: 12 additions & 10 deletions src/fordpass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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');
}
Expand Down

0 comments on commit c4a6fd4

Please sign in to comment.