Investigando por la web encentré esta clase.
elance-auth-lib.php
Código PHP:
Ver original<?php
class ElanceAuthentication {
public $CurlHeaders;
public $ResponseCode;
private $_AuthorizeUrl = "https://api.elance.com/api2/oauth/authorize";
private $_AccessTokenUrl = "https://api.elance.com/api2/oauth/token";
public function __construct() {
$this->CurlHeaders = array(); $this->ResponseCode = 0;
}
public function RequestAccessCode ($client_id, $redirect_url) {
return($this->_AuthorizeUrl . "?client_id=" . $client_id . "&response_type=code&redirect_uri=" . $redirect_url);
}
// Convert an authorization code from an Elance callback into an access token.
public function GetAccessToken($client_id, $client_secret, $auth_code) {
// Init cUrl.
$r = $this->InitCurl($this->_AccessTokenUrl);
// Add client ID and client secret to the headers.
"Authorization: Basic " . base64_encode($client_id . ":" . $client_secret), ));
// Assemble POST parameters for the request.
$post_fields = "code=" . urlencode($auth_code) . "&grant_type=authorization_code";
// Obtain and return the access token from the response.
if ($response == false) {
}
//Parse JSON return object.
}
private function InitCurl($url) {
$r = null;
header("HTTP/1.1 500", true, 500); die("Cannot initialize cUrl session. Is cUrl enabled for your PHP installation?"); }
// Decode compressed responses.
// NOTE: If testing locally, add the following lines to use a dummy certificate, and to prevent cUrl from attempting to verify
// the certificate's authenticity. See http://richardwarrender.com/2007/05/the-secret-to-curl-in-php-on-windows/ for more
// details on this workaround. If your server has a valid SSL certificate installed, comment out these lines.
curl_setopt($r, CURLOPT_CAINFO
, "C:\wamp\bin\apache\Apache2.2.21\cacert.crt");
// NOTE: For Fiddler2 debugging.
//curl_setopt($r, CURLOPT_PROXY, '127.0.0.1:8888');
return($r);
}
// A generic function that executes an Elance API request.
public function ExecRequest($url, $access_token, $get_params) {
// Create request string.
$r = $this->InitCurl($url);
));
if ($response == false) {
}
//Parse JSON return object.
}
}
?>
user-authentification.php
Código PHP:
Ver original<?php
require_once('elance-auth-lib.php');
$elance_auth = new ElanceAuthentication();
$url = $elance_auth->RequestAccessCode("4eb1de8bf06b10210e000005", "http://localhost/test/callback.php");
?>
callback.php
Código PHP:
Ver original<?php
require_once('elance-auth-lib.php');
if (!isset($_GET["code"])) { die("Require the code parameter to validate!"); }
$code = $_GET["code"];
$elance_auth = new ElanceAuthentication();
$json = $elance_auth->GetAccessToken("4eb1de8bf06b10210e000005", "M5IqdtQdZN8cX741OkBniA", $code);
//Output code
echo "<p>Access token is " . $json->data->access_token . "<p/>";
?>
Puede servir para conectarme por medio de OAuth2 a una api ? sepan disculpar ya que estoy un poco perdido con este tema.
Desde ya muchas gracias.