Skip to content

Instantly share code, notes, and snippets.

@kawahara
Created April 15, 2010 10:53
Show Gist options
  • Save kawahara/366967 to your computer and use it in GitHub Desktop.
Save kawahara/366967 to your computer and use it in GitHub Desktop.
<?php
include_once 'lib/OAuth.php';
class OAuthSignatureMethod_RSA_SHA1_opOpenSocialPlugin extends OAuthSignatureMethod_RSA_SHA1
{
protected function fetch_private_cert(&$request) {
}
protected function fetch_public_cert(&$request) {
return <<<EOT
-----BEGIN CERTIFICATE-----
....
-----END CERTIFICATE-----
EOT;
}
}
$request = OAuthRequest::from_request(null, null, null);
$signature_method = new OAuthSignatureMethod_RSA_SHA1_opOpenSocialPlugin();
if (!$signature_method->check_signature($request, null, null, $request->get_parameter('oauth_signature')))
{
exit;
}
define('CONSUMER_KEY', '#CONSUMER_KEY#');
define('CONSUMER_SECRET', '#CONSUMER_SECRET#');
define('BASE_URL', '#SNS_URL#');
$consumer = new OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
$request = OAuthRequest::from_consumer_and_token(
$consumer,
null,
'GET',
BASE_URL.'/api.php/social/rest/people/@me/@self'
);
$request->set_parameter('xoauth_requestor_id', $_GET['opensocial_owner_id']);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$res = do_get($request->get_normalized_http_url(), $request->to_postdata());
$json = json_decode($res, true);
if ($_GET['refid'])
{
echo 'あなたのIDは'.$json['entry']['id'].'です。<br>';
echo "<img src=\"".$json['entry']['thumbnailUrl']."\">";
echo "<a href=\"?url=".urlencode("http://debian/oauth/mobile.php")."\" utn>画面遷移!</a>";
}
else
{
echo $json['entry']['displayName']."さんこんにちは<br>";
echo "<a href=\"?url=".urlencode("http://debian/oauth/mobile.php?refid=1")."\">画面遷移!</a>";
}
function do_get($uri, $data = '')
{
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $uri.'?'.$data);
curl_setopt($h, CURLOPT_POST, false);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($h);
curl_close($h);
return $result;
}
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Mobile Test - 1" description="Mobile Test">
<Link rel="event.addapp" href="http://debian/oauth/t.php" method="POST" />
<Link rel="event.removeapp" href="http://debian/oauth/t.php" method="POST" />
</ModulePrefs>
<Content type="url" view="mobile" href="http://debian/oauth/mobile.php" />
</Module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment