公開した。
HTTP_OAuthConsumer - Openpear
http://openpear.org/package/HTTP_OAuthConsumer
Revision 1978: /HTTP_OAuthConsumer/trunk
http://svn.openpear.org/HTTP_OAuthConsumer/trunk/
機能
HTTP_OAuthとの主な違いは、シグネチャ方式に、HMAC-SHA1だけじゃなく、RSA-SHA1にも対応してる所。
需要があるかどうかは解らないけど。
HTTPリクエストには、HTTP_Request2を使った。
というか、継承した。
だからほぼ1から書き直しになってしまった…。
あんまりテストしてないからバグあるかも…?
HTTP_Request2はGETパラメータを扱いにくい。
addPostParameter()っぽい感じでaddGetParameter()を追加した。
やっぱりNet_Curl2使った方がよかったかなと思ったけど、眠いしめんどくさくなっちゃったから公開した。
インストール
Openpearのチャンネル追加。
[root@localhost ~]# pear channel-discover openpear.org Adding Channel "openpear.org" succeeded Discovery of channel "openpear.org" succeeded
HTTP_Request2をインストール。
[root@localhost ~]# pear install pear install HTTP_Request2
HTTP_OAuthConsumerをインストール。
[root@localhost ~]# pear upgrade openpear/HTTP_OAuthConsumer downloading HTTP_OAuthConsumer-1.0.1.tgz ... Starting to download HTTP_OAuthConsumer-1.0.1.tgz (2,927 bytes) ....done: 2,927 bytes upgrade ok: channel://openpear.org/HTTP_OAuthConsumer-1.0.1
example
HMAC-SHA1方式でGETメソッドのOAuthリクエストを送るサンプル。
<?php require_once('HTTP/OAuthConsumer.php'); try { $oauth = HTTP_OAuthConsumer::factory(); $oauth->setURL('http://example.com/?format=json'); $oauth->addGetParameter('aaa', 'AAA'); $oauth->setConsumer('testuser', 'testpass'); $res = $oauth->send(); print_r($res); } catch(Exception $e) { echo $e->getMessage(); } echo "\n";
サンプルは、この辺にいくつか用意した。
http://svn.openpear.org/HTTP_OAuthConsumer/trunk/example/
TODO
RSA-SHA1のテストをする。
RSA-SHA1のサンプルを用意する。
HTTP_OAuthProviderを公開する。(というか、作る)
とりあえず、パッケージ名を予約しといた。
HTTP_OAuthProvider - Openpear
http://openpear.org/package/HTTP_OAuthProvider
追記 2010-08-05 04:39:34
RSA-SHA1のテストした。
RSA-SHA1のサンプルも用意した。
RSAキーの生成方法も書いた。
example
RSA-SHA1方式でGETメソッドのOAuthリクエストを送るサンプル。
<?php require_once('HTTP/OAuthConsumer.php'); try { $privatekey = file_get_contents('private.key'); $oauth = HTTP_OAuthConsumer::factory('RSA-SHA1'); $oauth->setURL('http://example.com/?format=json'); $oauth->addGetParameter('aaa', 'AAA'); $oauth->setConsumer('testuser', $privatekey); $res = $oauth->send(); print_r($res); } catch(Exception $e) { echo $e->getMessage(); } echo "\n";