Giter Club home page Giter Club logo

connected-car-node-sdk's Introduction

ConnectedCar Node SDK Logo

The ConnectedCar JavaScript SDK is an open-source, python package that provides the ability to send commands to your Ford Sync Connect (Ford Pass) connected vehicle.

Installation

npm install connected-car

Requirements

  • To make requests to a vehicle, the end user must have signed up for an account using Ford Pass. These credentials will be used to authenticate your requests.

Getting Started

Import the ConnectedCar SDK

import connectedcar from 'connected-car';

Create a new connectedcar client

  • Note the default ConnectedCar client_id is 9fb503e0-715b-47e8-adfd-ad4b7770f73b
const client = connectedcar.AuthClient('9fb503e0-715b-47e8-adfd-ad4b7770f73b', {region: 'US'}); // Region argument is only required if you live outside the United States.
  • Note: If your region is outside of the US you can pass different region parameters to the User class. Regions: (US, CA, EU, AU)

Use client.getAccessTokenFromCredentials() to exchange your user credentials for an token object. To make any vehicle data request to the Ford Sync Connect API, you'll need to give the SDK a valid access token.

const token = await client.getAccessTokenFromCredentials({
  username: '<username>',
  password: '<password>',
});

Access tokens will expire every 2 hours, so you'll need to constantly refresh them by calling client.getAccessTokenFromRefreshToken()

const refreshToken = await client.getAccessTokenFromRefreshToken(token.getRefreshToken());

With your access token in hand, use connectedcar.User() to get a User object representing the user.

const user = connectedcar.User(token.getValue());

Use user.vehicles() to return an array of all the vehicles associated with a users account. The response will include the vehicle vin.

const vehicles = await user.vehicles();

const vehicleList = []; // Array of vehicles

for (userVehicle of vehicles) // For each user vehicle
  vehicleList.push(userVehicle['VIN']);

Now with a vehicle vin in hand, use connectedcar.Vehicle() to get a Vehicle object representing the user's vehicle.

let currentVehicle = connectedcar.Vehicle(vehicleList[0], token.getValue());

Now you can ask the car to do things, or ask it for some data! For example:

await currentVehicle.start();

Examples & Documentation

For more examples on what you can do with your ConnectedCar, see the examples folder or take a peek at the documentation.

Funding & Support

If you are interested in supporting the development of my projects check out my patreon or buy me a coffee.

Disclaimer

THIS CODEBASE IS NOT ENDORSED, AFFILIATED, OR ASSOCIATED WITH FORD, FOMOCO OR THE FORD MOTOR COMPANY.

connected-car-node-sdk's People

Contributors

brandon-grant avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

connected-car-node-sdk's Issues

404 v1 is deprecated.

I'm getting the following error when trying to authenticate and get a fresh token:
"404 v1 is deprecated."

Getting 400/500 error when trying to login

I'm getting the following error when trying to login

ConnectedCarException: status 400 reading FigAuthTokenvalidationApi#validateToken(DashBoardServiceIdentityToken,String,String); response : feign.Response$InputStreamBody@a129a9e
    at D:\Node JS\Mazda\node_modules\connected-car\dist\Api\Api.js:75:23
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  SyncErrorStatus: 500,
  SyncErrorMessage: 'status 400 reading FigAuthTokenvalidationApi#validateToken(DashBoardServiceIdentityToken,String,String); response : feign.Response$InputStreamBody@a129a9e'
}

Here is the code i used

    login = async (username, password) => {
        token = await client.getAccessTokenFromCredentials({
            username,
            password
        });
        user = ConnectedCar.User(token);
        let vehicles = await user.vehicles();
        for (userVehicle of vehicles) {
            const Vehicle = {
                id: userVehicle.VIN,
            };
            vehicleList.push(Vehicle)
        }
    }

`user.getVehicles` doesn't work (400)

When executing user.getVehicles you get a statuscode 400 (bad request)
To Reproduce Steps to reproduce the behavior:

i've created this function:

async function getVehicles(user) {
  const vehicles = await user.vehicles();
  const vehicleList = []; 
  for (userVehicle of vehicles)
  vehicleList.push(userVehicle['VIN']);

  return vehicleList;
}

Sadly it returns a 400 on await user.vehicles();
Note: Token- and user- calls work perfectly fine. We get a token and a User with success.

I'd expect to get a list of vehicles

image

Desktop (please complete the following information):

  • OS: Windows 10
  • NodeJS (Plain)

Access Denied - fetchAuthorizationCode

When trying to get an access token, I get an error message in fetchAuthorizationCode:
fordapp://userauthorized?error_description=CSIAQ0159E+You+are+not+authorized+to+access+this+protected+resource.&error=access_denied

All calls before that are going just fine so I think it's really the fetchAuthorizationCode that's not working out properly.
The GET is done with a proper-looking URL I got from Ford:
https://sso.ci.ford.com/oidc/endpoint/default/authorize?qsId=d9aa5f49-92a3-40e1-8edc-BLAAT&client_id=9fb503e0-715b-47e8-adfd-ad4b7770f73b&identity_source_id=BLAAT

I would assume that if something went wrong in the process before that, Ford would throw an error earlier.
Anyone got a clue if this is again Ford messing up? Their latest app update also crashes after logging in 'fresh'...

What's wrong with this request?

Not a bug, but a development question. I've re-implemented this api for evcc-io/evcc#4477 and fail to update to the latest changes from #35. Could I kindly ask you for advise what's wrong with this request? I can't seem to find any difference with this repo, yet always end in HTTP 404.

POST /api/expdashboard/v1/details HTTP/1.1
Host: api.mps.ford.com
User-Agent: FordPass/5 CFNetwork/1333.0.4 Darwin/21.5.0
Content-Length: 51
Accept: application/json
Application-Id: 1E8C7794-FF5F-49BC-9596-A1E0C86C5B19
Auth-Token: eyJ0...
Content-Type: application/json
Countrycode: EUR
Accept-Encoding: gzip

{"dashboardRefreshRequest":"All","smsWakeUpVIN":""}

Much appreciated, thank you!

Authentication Issue

Looks like Ford has disabled the OAuth password grant based on the error response CSIAQ0172E The grant type [password] is not supported. Supported grant types are [authorization_code, refresh_token].

Looking into a solution!

Deploy in AWS Lambda

I’d like to deploy this in AWS Lambda. I have some experience deploying small NodeJS functions, but have never deployed a python function. I imagine this might be a popular deployment option, so from a feature request perspective it would be great if the documentation included a “how to” get it running up there. I’m going to give it a whirl myself, but any time saving tips would be greatly appreciated.

Status is returning forbidden

When calling status on a vehicle, a 403/forbidden response is being returned from Ford.

A simple example:

import connectedcar from 'connected-car';

const client = connectedcar.AuthClient('9fb503e0-715b-47e8-adfd-ad4b7770f73b'); 

const token = await client.getAccessTokenFromCredentials({
  username: '*****',
  password: '****',
});

const refreshToken = await client.getAccessTokenFromRefreshToken(token.getRefreshToken());
const user = connectedcar.User(token.getValue());
const vehicles = await user.vehicles();

const vehicleList = []; // Array of vehicles

for (let userVehicle of vehicles) // For each user vehicle
  vehicleList.push(userVehicle['VIN']);

let currentVehicle = connectedcar.Vehicle(vehicleList[0], token.getValue());

console.log(currentVehicle);
const status = await currentVehicle.status();
console.log(status);

401 - Authorization Issue

Ford changed the FordPass authentication endpoint. The Ford authorization endpoint will now only generate proper access tokens using the OAuth 2.0 Authorization Code Grant.

Ford Account Lockout

Hi all,

It seems Ford has started cracking down on third party services taking advantage of their apis.

Recently I was locked out of my account and after speaking to Ford support they told me it was because of an unauthorized third party service using my credentials, which would be connected-car SDK's.

I am curious if anyone else has experienced this issue?

Access denied upon fetchAuthorizationCode

When trying to get an access token, I get an error message in fetchAuthorizationCode:
fordapp://userauthorized?error_description=CSIAQ0159E+You+are+not+authorized+to+access+this+protected+resource.&error=access_denied

All calls before that are going just fine so I think it's really the fetchAuthorizationCode that's not working out properly.
The GET is done with a proper-looking URL I got from Ford:
https://sso.ci.ford.com/oidc/endpoint/default/authorize?qsId=d9aa5f49-92a3-40e1-8edc-BLAAT&client_id=9fb503e0-715b-47e8-adfd-ad4b7770f73b&identity_source_id=BLAAT

I would assume that if something went wrong in the process before that, Ford would throw an error earlier.
Anyone got a clue if this is again Ford messing up? Their latest app update also crashes after logging in 'fresh'...

Add support for proxy

Is your feature request related to a problem? Please describe. A clear and concise description
of what the problem is. Ex. I'm always frustrated when [...]

I would like to request for a proxy feature.

Describe the solution you'd like A clear and concise description of what you want to happen.
Currently it works locally but when I run the program in digitalocean, it gets blocked.

Describe alternatives you've considered A clear and concise description of any alternative
solutions or features you've considered.

I had previously made it work in php using proxy, but recently they changed their auth flow. So I can't just always keep on changing
things. So i am using this package but it lacks proxy feature.

Additional context Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.