Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid_grant on request when obtaining access_token from somewhere else #70

Open
maakle opened this issue Oct 16, 2017 · 3 comments
Open

Comments

@maakle
Copy link

maakle commented Oct 16, 2017

Hello,
I have an iOS App where I use SSO to authenticate the user and then save the accessToken & refreshToken locally to keychain on my device. Then I'm calling my server who uses a javascript background function to call your library to make a request to Uber.
So far, I'm trying to set up your library with my 2 local tokens like this:

 var uber = new uberClient({
    client_id: '...',
    client_secret: '...',
    server_token: '...',
    name: 'My App',
    sandbox: true, //optional
    access_token: accessToken,
    refresh_token: refreshToken
  });

afterwards I want to call the uber.requests.getEstimatesAsync endpoint like this:

uber.requests.getEstimatesAsync({
      "start_latitude": pickupLocation["lat"],
      "start_longitude": pickupLocation["lng"],
      "end_latitude": dropoffLocation["lat"],
      "end_longitude": dropoffLocation["lng"]
      })
      .then(function(res) { 
        console.log(JSON.stringify(res)); 
      })
      .error(function(err) { 
        console.error(err); 
      });
})

Though every time I get an "invalid_grant" error while doing this. Did I make a mistake authenticating myself or setting up the Uber client wrong? Is it even possible to add my local accessToken & refreshToken manually to your uber client?
I'm using a Developer account for doing this, therefore I should actually have all the required permissions for the request endpoint, but I also obtained them previously in the App.

Best regards,
Matt

@MAKEADM
Copy link

MAKEADM commented Oct 17, 2017

Hello, currently i have the same issue.

@supermarioim
Copy link

I also have same issue. Tried setting access_token with
uber.access_token = 'xxx'
and in init options and all the same, i always get "invalid_grant" error.
I'm using latest version of module.

@maakle
Copy link
Author

maakle commented Oct 26, 2017

So I think it's a problem with the library itself. Because once I made the request with http with the "request" library (https://github.com/request/request) it worked. Include for that at the top of your code:

var request = require('request');

Both OAuth2 and SSO accessToken worked. You should give the method a pickupLocation with latitude and longitude and your obtained accessToken from Uber like this:

function getAllAvailableUberProducts(pickupLocation, accessToken){
    var lat = pickupLocation["lat"].toString();
    var lng = pickupLocation["lng"].toString();

    var options = {
        uri: "https://api.uber.com/v1.2/products?latitude="+lat+"&longitude="+lng,
        method: 'GET',
        headers: {
            "Authorization": "Bearer " + accessToken,
            "Accept-Language": "en_US",
            "Content-Type": "application/json"
        }
    };

    request(options, function (error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log(JSON.parse(body).products);
        } else {
            console.log(error);
        }
    });
}

I hope this helps someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants