-
-
Save nesquena/744ec29faba42625abc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once "oauth-php/library/OAuthStore.php"; | |
include_once "oauth-php/library/OAuthRequester.php"; | |
// TODO Fill these out... | |
$consumer_key = '4WNiWlmiqhq2VAbPE6xv0'; // this is your consumer key | |
$secret = 'xq0ztj4D0evWXkgqONud4cXiq3lpEBnB39d6HN0Li'; // this is your secret key | |
// TODO fill this in | |
$options = array('server' => 'localhost', 'username' => 'root', | |
'password' => '', 'database' => 'php_test'); | |
$store = OAuthStore::instance('MySQL', $options); | |
$user_id = 1; | |
// Request parameters are oauth_token, consumer_key and usr_id. | |
$oauth_token = $_GET['oauth_token']; | |
$oauth_verifier = $_GET['oauth_verifier']; | |
try | |
{ | |
OAuthRequester::requestAccessToken($consumer_key, $oauth_token, $user_id, 'POST', $_GET); | |
} | |
catch (OAuthException $e) | |
{ | |
// Something wrong with the oauth_token. | |
// Could be: | |
// 1. Was already ok | |
// 2. We were not authorized | |
} | |
// The request uri being called. | |
$request_uri = 'http://gomiso.com/api/oauth/v1/users/show.json'; | |
// Parameters, appended to the request depending on the request method. | |
// Will become the POST body or the GET query string. | |
$params = array(); | |
// Obtain a request object for the request we want to make | |
$req = new OAuthRequester($request_uri, 'GET', $params); | |
// Sign the request, perform a curl request and return the results, throws OAuthException exception on an error | |
$result = $req->doRequest($user_id); | |
// $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string) | |
print_r ($result); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once "oauth-php/library/OAuthStore.php"; | |
include_once "oauth-php/library/OAuthRequester.php"; | |
$consumer_key = '4WNiWlmiqhq2VAbPE6xv0'; // this is your consumer key | |
$secret = 'xq0ztj4D0evWXkgqONud4cXiq3lpEBnB39d6HN0Li'; // this is your secret key | |
// TODO fill this in | |
$options = array('server' => 'localhost', 'username' => 'root', | |
'password' => '', 'database' => 'php_test'); | |
$store = OAuthStore::instance('MySQL', $options); | |
// The server description | |
$server = array( | |
'consumer_key' => $consumer_key, | |
'consumer_secret' => $secret, | |
'server_uri' => 'http://gomiso.com/', | |
'signature_methods' => array('HMAC-SHA1', 'PLAINTEXT'), | |
'request_token_uri' => 'http://gomiso.com/oauth/request_token', | |
'authorize_uri' => 'http://gomiso.com/oauth/authorize', | |
'access_token_uri' => 'http://gomiso.com/oauth/access_token' | |
); | |
$user_id = 1; | |
// Save the server in the the OAuthStore | |
$consumer_key = $store->updateServer($server, $user_id); | |
// Callback to our (consumer) site, will be called when the user finished the authorization at the server | |
$callback_uri = 'http://somedomain.com/callback.php'; // TODO FIX THIS | |
// Obtain a request token from the server | |
$token = OAuthRequester::requestRequestToken($consumer_key, $user_id, array('oauth_callback' => $callback_uri)); | |
// Now redirect to the autorization uri and get us authorized | |
if (!empty($token['authorize_uri'])) | |
{ | |
// Redirect to the server, add a callback to our server | |
if (strpos($token['authorize_uri'], '?')) | |
{ | |
$uri = $token['authorize_uri'] . '&'; | |
} | |
else | |
{ | |
$uri = $token['authorize_uri'] . '?'; | |
} | |
$uri .= 'oauth_token='.rawurlencode($token['token']); | |
} | |
else | |
{ | |
// No authorization uri, assume we are authorized, exchange request token for access token | |
$uri = $callback_uri . '&oauth_token='.rawurlencode($token['token']); | |
} | |
header('Location: '.$uri); | |
exit(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment