I've been trying for the past few days to integrate my app with uber, but for some reason during the oauth2 authentication I can't get uber to give me a valid token. I can get an access code but when using curl, I can't seem to get an access token, no matter how I arrange my script. Here's what I have:
<?php
echo $_GET['code']."<br>";
$token = curl_init();
$param = array(
'client_secret' => 'MY_SECRET',
'client_id' => 'MY_ID',
'grant_type' => 'authorization_code',
'code' => "{$_GET['code']}"
);
$postData = '';
foreach($param as $k => $v)
{
$postData .= $k . '='.urlencode($v).'&';
}
$postData = rtrim($postData, '&');
curl_setopt($token, CURLOPT_URL, 'https://login.uber.com/oauth/token');
curl_setopt($token, CURLOPT_HEADER, true);
curl_setopt($token, CURLOPT_RETURNTRANSFER, true);
curl_setopt($token, CURLOPT_POST, true);
curl_setopt($token, CURLOPT_POSTFIELDS, $postData);
$returned_token = curl_exec($token);
curl_close($token);
echo $returned_token;
?>
I've double checked my secret and id, both are correct. I can see each time I'm going to get the access code it's something unique, I can see it echoed out on the authorization page I'm redirecting to, but no matter what I keep getting the response as:
{"error": "access_denied"}
This error happens because:
as the documentation for the GET https://login.uber.com/oauth/v2/authorize says:
Works fine for me. Make sure the
Content-Type
header is correct. Some services will expect that. (e.g.Content-Type=x-www-form-urlencoded
)Also, can yo share how you are requesting the
code
? (e.g. whichscope
are you using when sending the Authorization request, etc).I've also encountered this problem and it looks like I found the reason of it.
Try adding redirect_uri (the same as in app settings) to your request, so your params code should look like this:
That helped me, but I hope Uber developers will make this error more specific
It worked for me perfectly. My problem was that I had a difference between the Url Redirect on Dashboard app and The parameter that i send to the request. I fixed it and everything works fine