Reputation: 71
Why do I get the error request uri?
https://login.uber.com/oauth/v2/authorize?response_type=code&client_id=".$settings['global']['clientId'].'&clientSecret="'.$settings['global']['clientSecret'].'&scope=all_trips&redirect_uri=http://'.$_SERVER['HTTP_HOST'].'token.php
Upvotes: 0
Views: 599
Reputation: 71
1) надо работать с например http://localhost/loacation.php( )
2) не надо вырезать лишние символы из переменной code
require_once 'uber.php'; $settings = require_once 'settings.php'; if ( !isset( $_GET["code"] ) ) { setcookie( "AccessToken", "", time() - 3600); Header( "Location: https://login.uber.com/oauth/v2/authorize?response_type=code&client_id=".$settings['global']['client_id'].'&redirect_uri=localhost/location.php&client_secret='.$settings['global']['client_secret']); die(); }
$result = postKeys("https://login.uber.com/oauth/v2/token",
array(
'client_secret'=>$settings['global']['client_secret'],
'client_id'=>$settings['global']['client_id'],
'grant_type'=> 'authorization_code',
'redirect_uri'=> 'http://localhost/location.php',
'code'=> $_GET["code"],
), array('Content-type: application/x-www-form-urlencoded')
);
// после получения ответа, проверяем на код 200, и если все хорошо, то у нас есть токен
if ($result["code"]==200) {
$result["response"]=json_decode($result["response"],true);
$token=$result["response"]["access_token"];
$new = new Token($settings);
$new->setToken($token);
}else
echo "не правильный код: ".$result["code"].' '.$result['response'];
Upvotes: 0
Reputation: 6559
For the GET /oauth/v2/authorize endpoint the clientSecret parameter that you send is not required and may interfere with some parameter validation on their backend. The parameters you need to pass are:
response_type
client_id
scope
state
redirect_uri
Read the above URL to understand what each parameter means.
Make sure the base of the URI you send in the query parameter redirect_uri to the GET https://login.uber.com/oauth/v2/authorize endpoint matches the one defined in the Uber Developers Dashboard for your app, Authorizations tab.
As the docs for the authorize OAuth request says:
redirect_uri (optional) The URI we will redirect back to after an authorization by the resource owner.
The base of the URI must match the redirect_uri used during the registration of your application.
The redirect URL can be:
any HTTPS:// URL
https://
a custom scheme
custom-scheme://
Make sure your redirect URI is HTTPS enabled
According to the same authorization and authentication documentation:
The Uber API implements the OAuth 2.0 standard for secure authentication and authorization.
All communication with our servers must be over SSL (https://).
For getting a TLS certificate at no cost for your domain I recommend Let's Encrypt Certificate Authority
Upvotes: 0