Client Access Token Authorization
¶ Overview
Uber APIs support the OAuth 2.0 authentication and authorization mechanisms to gain access to respective APIs.
¶ Client Access Token authentication
The Uber API uses OAuth 2.0 to allow developers to get a client access token to access users data. OAuth 2.0 is a specification outlined in RFC 6749 that allows third-party services to make requests on behalf of a user without accessing passwords and other sensitive information. If you are unfamiliar with OAuth 2.0, check out Aaron Parecki’s “OAuth 2 Simplified” guide.
OAuth 2.0 endpoints
Authorization Host | https://auth.uber.com |
---|---|
Token Endpoint | https://auth.uber.com/oauth/v2/token |
¶ Setup
To initially set your application up, follow these two guides which will show how can you configure your application and test accordingly.
¶ Step 1: Get Token using Client Credentials
After initially setting your application up, you are going to be able to retrieve your Access Token using your client_id
and your client_secret
generated in the developer.uber.com Dashboard.
Example Request:
curl -F 'client_secret=<CLIENT_SECRET>' \
-F 'client_id=<CLIENT_ID>' \
-F 'grant_type=client_credentials' \
-F 'scope=<space_delimited_scopes>'
https://auth.uber.com/oauth/v2/token
Example Response:
{
"access_token": "xxxx",
"expires_in": 2592000,
"token_type": "Bearer",
"refresh_token": "xxxx",
"scope": "<space_delimited_scopes>"
}
The access_token
is valid for the time described by expires_in
(in seconds). The refresh_token
expires after one year and can be used to obtain a new access_token
at any time given that your application is still authorized to access the API on behalf of this user.
¶ Step 2: Use bearer token
Pass the access_token
returned in the previous step as a bearer token in the Authorization header.
curl -X POST \
-H 'Authorization: Bearer <access_token>' \
-d '{"id":"<your_client_id>"}' \
'https://api.uber.com/v1/mirror/external/echo'
¶ Refresh Token
When the access_token
has expired or before it, you can obtain a new access_token
by exchanging the refresh_token
associated with the access_token
. Note: The Client ID must match the Client ID from the Client Credentials Token flow.
curl -F 'client_secret=<CLIENT_SECRET>' \
-F 'client_id=<CLIENT_ID>' \
-F 'grant_type=refresh_token' \
-F 'refresh_token=REFRESH_TOKEN' \
https://auth.uber.com/oauth/v2/token
¶ Revoke Token
To revoke your pre-generated access or refresh token for client credentials grant type, you must use the following route, using the same client_id
and client_secret
used in the past requests. Use the following cURL to revoke your tokens:
curl -F 'client_secret=<CLIENT_SECRET>' \
-F 'client_id=<CLIENT_ID>' \
-F 'token=<TOKEN>' \
https://auth.uber.com/oauth/revoke
¶ Debugging & authentication errors
Error | Description |
---|---|
invalid_request |
Required parameters were not provided. |
invalid_client |
The client ID or secret provided is invalid. |
invalid_grant |
Valid grant types are authorization_code and refresh_token |
invalid_scope |
The scope parameter provided is not a valid subset of scopes. |
too_many_requests |
The user has called the Token endpoint with the client_credentials grant type more than 100 times in an hour |
server_error |
The server returned an unknown error. |
temporarily_unavailable |
The endpoint is temporarily unable to respond. |