7 Commits
1.0.9 ... 1.0.6

Author SHA1 Message Date
Eher
79300e5a58 Create test to Request and Consumer 2012-12-03 02:12:52 -02:00
Eher
9d2d8b0c1e Put Travis-ci status image in Readme 2012-12-02 21:42:40 -02:00
Eher
15df1e0e0d Create test skeleton with PHPUnit and Travis-CI 2012-12-02 21:40:34 -02:00
Eher
b37f971fd7 Put vendor folder in gitignore 2012-12-02 21:39:43 -02:00
Eher
b24d52eb34 Rename OAuthConsumer to Consumer 2012-12-02 18:23:07 -02:00
Eher
e3aea01134 Rename OAuthRequest to Request 2012-12-02 18:21:23 -02:00
Eher
663f81f35b Fix composer.json syntax 2012-12-02 18:15:55 -02:00
11 changed files with 94 additions and 14 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
*.swp *.swp
composer.phar composer.phar
composer.lock composer.lock
vendor

9
.travis.yml Normal file
View File

@@ -0,0 +1,9 @@
language: php
php:
- 5.3
- 5.4
before_script:
- wget -c http://getcomposer.org/composer.phar
- php composer.phar install

View File

@@ -1,3 +1,3 @@
#OAuth 1 PHP Library #OAuth 1 PHP Library[![Build Status](https://secure.travis-ci.org/EHER/OAuth.png?branch=master)](http://travis-ci.org/EHER/OAuth)
Based on [Andy Smith's](http://term.ie/) [basic php library](http://oauth.googlecode.com/svn/code/php/) for OAuth. Based on [Andy Smith's](http://term.ie/) [basic php library](http://oauth.googlecode.com/svn/code/php/) for OAuth.

View File

@@ -1,6 +1,8 @@
{ {
"name": "Eher/OAuth", "name": "eher/oauth",
"type": "library", "type": "library",
"license": "BSD-3-Clause",
"description": "OAuth 1 PHP Library",
"require": { "require": {
"php": ">=5.3.0" "php": ">=5.3.0"
}, },
@@ -8,5 +10,8 @@
"psr-0": { "psr-0": {
"Eher\\OAuth": "src" "Eher\\OAuth": "src"
} }
},
"require-dev": {
"eher/phpunit": "1.6"
} }
} }

7
phpunit.xml.dist Normal file
View File

@@ -0,0 +1,7 @@
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Test Suite">
<directory>test</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -13,7 +13,7 @@ function __construct($key, $secret, $callback_url=NULL) {
} }
function __toString() { function __toString() {
return "OAuthConsumer[key=$this->key,secret=$this->secret]"; return "Consumer[key=$this->key,secret=$this->secret]";
} }
} }

View File

@@ -94,7 +94,7 @@ private function get_version(&$request) {
* figure out the signature with some defaults * figure out the signature with some defaults
*/ */
private function get_signature_method($request) { private function get_signature_method($request) {
$signature_method = $request instanceof OAuthRequest $signature_method = $request instanceof Request
? $request->get_parameter("oauth_signature_method") ? $request->get_parameter("oauth_signature_method")
: NULL; : NULL;
@@ -119,7 +119,7 @@ private function get_signature_method($request) {
* try to find the consumer for the provided request's consumer key * try to find the consumer for the provided request's consumer key
*/ */
private function get_consumer($request) { private function get_consumer($request) {
$consumer_key = $request instanceof OAuthRequest $consumer_key = $request instanceof Request
? $request->get_parameter("oauth_consumer_key") ? $request->get_parameter("oauth_consumer_key")
: NULL; : NULL;
@@ -139,7 +139,7 @@ private function get_consumer($request) {
* try to find the token for the provided request's token key * try to find the token for the provided request's token key
*/ */
private function get_token($request, $consumer, $token_type="access") { private function get_token($request, $consumer, $token_type="access") {
$token_field = $request instanceof OAuthRequest $token_field = $request instanceof Request
? $request->get_parameter('oauth_token') ? $request->get_parameter('oauth_token')
: NULL; : NULL;
@@ -158,10 +158,10 @@ private function get_token($request, $consumer, $token_type="access") {
*/ */
private function check_signature($request, $consumer, $token) { private function check_signature($request, $consumer, $token) {
// this should probably be in a different method // this should probably be in a different method
$timestamp = $request instanceof OAuthRequest $timestamp = $request instanceof Request
? $request->get_parameter('oauth_timestamp') ? $request->get_parameter('oauth_timestamp')
: NULL; : NULL;
$nonce = $request instanceof OAuthRequest $nonce = $request instanceof Request
? $request->get_parameter('oauth_nonce') ? $request->get_parameter('oauth_nonce')
: NULL; : NULL;

View File

@@ -19,7 +19,7 @@ public function get_name() {
* - Chapter 9.4.1 ("Generating Signatures") * - Chapter 9.4.1 ("Generating Signatures")
* *
* Please note that the second encoding MUST NOT happen in the SignatureMethod, as * Please note that the second encoding MUST NOT happen in the SignatureMethod, as
* OAuthRequest handles this! * Request handles this!
*/ */
public function build_signature($request, $consumer, $token) { public function build_signature($request, $consumer, $token) {
$key_parts = array( $key_parts = array(

View File

@@ -16,10 +16,10 @@ abstract public function get_name();
/** /**
* Build up the signature * Build up the signature
* NOTE: The output of this function MUST NOT be urlencoded. * NOTE: The output of this function MUST NOT be urlencoded.
* the encoding is handled in OAuthRequest when the final * the encoding is handled in Request when the final
* request is serialized * request is serialized
* @param OAuthRequest $request * @param Request $request
* @param OAuthConsumer $consumer * @param Consumer $consumer
* @param OAuthToken $token * @param OAuthToken $token
* @return string * @return string
*/ */
@@ -27,8 +27,8 @@ abstract public function build_signature($request, $consumer, $token);
/** /**
* Verifies that a given signature is correct * Verifies that a given signature is correct
* @param OAuthRequest $request * @param Request $request
* @param OAuthConsumer $consumer * @param Consumer $consumer
* @param OAuthToken $token * @param OAuthToken $token
* @param string $signature * @param string $signature
* @return bool * @return bool

View File

@@ -0,0 +1,18 @@
<?php
namespace Eher\OAuth;
class ConsumerTest extends \PHPUnit_Framework_TestCase
{
public function testConsumer()
{
$consumer = null;
$consumer = new Consumer("ConsumerKey", "ConsumerSecret");
$this->assertEquals(
'Consumer[key=ConsumerKey,secret=ConsumerSecret]',
(string) $consumer
);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Eher\OAuth;
class RequestTest extends \PHPUnit_Framework_TestCase
{
public function testRequestToUrl()
{
$consumer = null;
$signatureMethod = null;
$request = null;
$once = "";
$timestamp = "";
$signature = "";
$expectedUrl = "";
$consumer = new Consumer('ConsumerKey', 'ConsumerSecret');
$signatureMethod = new HmacSha1();
$request = Request::from_consumer_and_token(
$consumer,
null,
"GET",
"http://www.endpoint.url/",
array()
);
$request->sign_request($signatureMethod, $consumer, null);
$once = $request->get_parameter('oauth_nonce');
$timestamp = $request->get_parameter('oauth_timestamp');
$signature = $request->get_parameter('oauth_signature');
$expectedUrl = "http://www.endpoint.url/?"
. "oauth_consumer_key=ConsumerKey"
. "&oauth_nonce=" . $once
. "&oauth_signature=" . Util::urlencode_rfc3986($signature)
. "&oauth_signature_method=HMAC-SHA1"
. "&oauth_timestamp=" . $timestamp
. "&oauth_version=1.0";
$this->assertEquals( $expectedUrl, (string) $request);
}
}