Skip to content

Instantly share code, notes, and snippets.

@jzazove
Created August 3, 2012 19:28
Show Gist options
  • Save jzazove/3250690 to your computer and use it in GitHub Desktop.
Save jzazove/3250690 to your computer and use it in GitHub Desktop.
Tip or Skip OAuth PHP Snippet
<?php
require 'OAuth.php';
$key = '<your_app_key>';
$secret = '<your_app_secret>';
$consumer = new OAuthConsumer($key, $secret);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1;
$my_domain = 'http://www.mydomain.net';
$callback_url = '/some_callback_url';
$api_endpoint_domain = 'https://tips.by';
$api_endpoint = $api_endpoint_domain . '/oauth/request_token';
$api_endpoint_signin = $api_endpoint_domain . '/oauth/authorize?oauth_token=';
$parameters = array('oauth_callback'=>$callback_url);
$req = OAuthRequest::from_consumer_and_token($consumer, null, "GET", $api_endpoint, $parameters);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$req->sign_request($sig_method, $consumer, null);
$a = $req->to_url();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $a);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
$token = OAuthUtil::parse_parameters($response);
//$_SESSION['oauth_token'] = $token['oauth_token'];
//$_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
echo '<a href="'. $api_endpoint_signin . $token['oauth_token'] . '">login</a>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment