Created
April 28, 2010 00:30
-
-
Save kawahara/381557 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 'lib/OAuth.php'; | |
define('CONSUMER_KEY', '#CONSUMER_KEY#'); | |
define('CONSUMER_SECRET', '#CONSUMER_SECRET#'); | |
define('BASE_URL', '#BASE_URL#'); | |
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----- | |
#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; | |
} | |
$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")."\">画面遷移!</a>"; | |
} | |
else | |
{ | |
echo $json['entry']['displayName']."さんこんにちは<br>"; | |
echo "<a href=\"invite:friends?callback=".urlencode('http://debian/oauth/mobile.php?refid=1')."\">招待ページ</a><br>"; | |
echo "<a href=\"?url=".urlencode("http://debian/oauth/mobile.php?refid=1")."\">画面遷移!</a><br>"; | |
} | |
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; | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<Module> | |
<ModulePrefs title="Mobile Test - 1" description="Mobile Test" author="Shogo Kawahara" /> | |
<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