Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
935c1f7709 | ||
![]() |
79300e5a58 | ||
![]() |
9d2d8b0c1e | ||
![]() |
15df1e0e0d | ||
![]() |
b37f971fd7 | ||
![]() |
b24d52eb34 | ||
![]() |
e3aea01134 | ||
![]() |
663f81f35b | ||
![]() |
6a15224e34 | ||
![]() |
c434283f5f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
*.swp
|
||||
composer.phar
|
||||
composer.lock
|
||||
vendor
|
||||
|
9
.travis.yml
Normal file
9
.travis.yml
Normal 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
|
@@ -1,3 +1,3 @@
|
||||
#OAuth 1 PHP Library
|
||||
#OAuth 1 PHP Library[](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.
|
||||
|
@@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "Eher/OAuth",
|
||||
"name": "eher/oauth",
|
||||
"type": "library",
|
||||
"license": "BSD-3-Clause",
|
||||
"description": "OAuth 1 PHP Library",
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
@@ -8,5 +10,8 @@
|
||||
"psr-0": {
|
||||
"Eher\\OAuth": "src"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"eher/phpunit": "1.6"
|
||||
}
|
||||
}
|
||||
|
7
phpunit.xml.dist
Normal file
7
phpunit.xml.dist
Normal file
@@ -0,0 +1,7 @@
|
||||
<phpunit bootstrap="vendor/autoload.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Test Suite">
|
||||
<directory>test</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
@@ -13,7 +13,7 @@ function __construct($key, $secret, $callback_url=NULL) {
|
||||
}
|
||||
|
||||
function __toString() {
|
||||
return "OAuthConsumer[key=$this->key,secret=$this->secret]";
|
||||
return "Consumer[key=$this->key,secret=$this->secret]";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -94,7 +94,7 @@ private function get_version(&$request) {
|
||||
* figure out the signature with some defaults
|
||||
*/
|
||||
private function get_signature_method($request) {
|
||||
$signature_method = $request instanceof OAuthRequest
|
||||
$signature_method = $request instanceof Request
|
||||
? $request->get_parameter("oauth_signature_method")
|
||||
: NULL;
|
||||
|
||||
@@ -119,7 +119,7 @@ private function get_signature_method($request) {
|
||||
* try to find the consumer for the provided request's consumer key
|
||||
*/
|
||||
private function get_consumer($request) {
|
||||
$consumer_key = $request instanceof OAuthRequest
|
||||
$consumer_key = $request instanceof Request
|
||||
? $request->get_parameter("oauth_consumer_key")
|
||||
: NULL;
|
||||
|
||||
@@ -139,7 +139,7 @@ private function get_consumer($request) {
|
||||
* try to find the token for the provided request's token key
|
||||
*/
|
||||
private function get_token($request, $consumer, $token_type="access") {
|
||||
$token_field = $request instanceof OAuthRequest
|
||||
$token_field = $request instanceof Request
|
||||
? $request->get_parameter('oauth_token')
|
||||
: NULL;
|
||||
|
||||
@@ -158,10 +158,10 @@ private function get_token($request, $consumer, $token_type="access") {
|
||||
*/
|
||||
private function check_signature($request, $consumer, $token) {
|
||||
// this should probably be in a different method
|
||||
$timestamp = $request instanceof OAuthRequest
|
||||
$timestamp = $request instanceof Request
|
||||
? $request->get_parameter('oauth_timestamp')
|
||||
: NULL;
|
||||
$nonce = $request instanceof OAuthRequest
|
||||
$nonce = $request instanceof Request
|
||||
? $request->get_parameter('oauth_nonce')
|
||||
: NULL;
|
||||
|
||||
@@ -175,7 +175,7 @@ private function check_signature($request, $consumer, $token) {
|
||||
$request,
|
||||
$consumer,
|
||||
$token,
|
||||
$signature
|
||||
Util::urldecode_rfc3986($signature)
|
||||
);
|
||||
|
||||
if (!$valid_sig) {
|
||||
|
@@ -19,7 +19,7 @@ public function get_name() {
|
||||
* - Chapter 9.4.1 ("Generating Signatures")
|
||||
*
|
||||
* 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) {
|
||||
$key_parts = array(
|
||||
|
@@ -16,10 +16,10 @@ abstract public function get_name();
|
||||
/**
|
||||
* Build up the signature
|
||||
* 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
|
||||
* @param OAuthRequest $request
|
||||
* @param OAuthConsumer $consumer
|
||||
* @param Request $request
|
||||
* @param Consumer $consumer
|
||||
* @param OAuthToken $token
|
||||
* @return string
|
||||
*/
|
||||
@@ -27,8 +27,8 @@ abstract public function build_signature($request, $consumer, $token);
|
||||
|
||||
/**
|
||||
* Verifies that a given signature is correct
|
||||
* @param OAuthRequest $request
|
||||
* @param OAuthConsumer $consumer
|
||||
* @param Request $request
|
||||
* @param Consumer $consumer
|
||||
* @param OAuthToken $token
|
||||
* @param string $signature
|
||||
* @return bool
|
||||
|
18
test/Eher/OAuth/ConsumerTest.php
Normal file
18
test/Eher/OAuth/ConsumerTest.php
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
40
test/Eher/OAuth/RequestTest.php
Normal file
40
test/Eher/OAuth/RequestTest.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user