2
votes

I am working on integrating Uber Server-side API using python. I am able to run the authorization flow successfully and get the Access Token.

With the received Access Token I am able to get information like user profile, user history. But whenever I do a ride request ( using Sandbox ), the following error occurs.

HTTP/1.1 **401 Unauthorized**<br/>
Server: nginx<br/>
Date: Tue, 03 May 2016 09:29:19 GMT<br/>
Content-Type: application/json<br/>
Content-Length: 75<br/>
Connection: keep-alive<br/>
X-Uber-App: uberex-sandbox<br/>
Strict-Transport-Security: max-age=0<br/>
X-Content-Type-Options: nosniff<br/>
X-XSS-Protection: 1; mode=block

{"message":"Invalid OAuth 2.0 credentials provided.","code":"unauthorized"}.

I am not able to find the what exactly I missing with. Can anyone suggest what might be the issue?

1

1 Answers

3
votes

The authorization error "unauthorized" in this case indicates that the access token you are using is not sufficient for the endpoint you are trying to call. Because you describe that the access token was valid for other endpoints such as GET /v1/me but is not for POST /v1/requests I would speculate that the access token was not authorized for the request scope.

You can check this in two ways:

  • In the token exchange response, the scopes that have been granted are listed.
  • If you are using v2 of Uber's OAuth, your access token is most likely a signed JWT. Use the debugger on JWT.io to see the scopes that your access token has been authorized for.

If the access token is in-fact missing the request scope, you just need to explicitly specify that scope when sending the user to the authorization url.

E.g. https://login.uber.com/oauth/v2/authorize?client_id=123&scopes=profile%20request...

Keep in mind that the request scope is a limited access scope, meaning you can authorize the owner and any of the registered developers of your OAuth app for it while in development. When ready for production, submit a request to Uber for approval with a demo of your completed app.