vendredi 25 août 2017

Laravel5 Oauth greePratform

I want to do Gree's Oauth authentication, but it does not work. How can I reproduce the sample code below using oriceon / oauth-5-laravel?

* The OAuth library used in this sample code: http: //code.google.com/p/oauth
* HTTP / Request 2 library used in this sample code: http: //pear.php.net/package/HTTP_Request 2


    $oauth_conf = $app_conf['oauth'];

$user_request = OAuthRequest::from_request(null, null, null);

$oauth_token          = $user_request->get_parameter('oauth_token');
$oauth_token_secret   = $user_request->get_parameter('oauth_token_secret');
$oauth_signature      = $user_request->get_parameter('oauth_signature');
$opensocial_viewer_id = $user_request->get_parameter('opensocial_viewer_id');
$xoauth_requestor_id  = $opensocial_viewer_id;


$endpoint_url = $oauth_conf['api.endpoint_url'] . '/people/@me/@self';
$http_method = 'GET';

$request_data = array();
$request_data['xoauth_requestor_id'] = $xoauth_requestor_id;

$signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$oauth_consumer = new OAuthConsumer($oauth_conf['consumer_key'], $oauth_conf['consumer_secret']);
$access_token   = new OAuthToken($oauth_token, $oauth_token_secret);
$oauth_request = OAuthRequest::from_consumer_and_token(
    $oauth_consumer, 
    $access_token, 
    $http_method, 
    $endpoint_url, 
    $request_data
);
$oauth_request->sign_request($signature_method, $oauth_consumer, $access_token);

$authorization_header_string = $oauth_request->to_header();
$authorization_header = substr($authorization_header_string, strlen('Authorization:'));

$http_options = array('timeout' => '10');
$http_request = new HTTP_Request2($endpoint_url, HTTP_Request2::METHOD_GET, $http_options);
$http_request->setHeader('Content-Type', "application/json");
$http_request->setHeader('Authorization', $authorization_header);

$url = $http_request->getUrl();
$url->setQueryVariable('xoauth_requestor_id', $xoauth_requestor_id);


$request_response = $http_request->send();

echo $request_response->getBody();






via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire