19 Commits

Author SHA1 Message Date
95477a7710 Merge pull request #9 from jacobkiers/update-travis-configuration
Update travis configuration: test PHP 5.3-5.6; 7 and HHVM.
2015-10-02 15:50:51 +02:00
e507a5dc8b Update travis configuration
Test more PHP versions, in order to maintain compatibility. Also updates
the composer install command.

Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2015-10-02 15:46:24 +02:00
11f934ee88 Merge pull request #8 from jacobkiers/fix-7-abstract-class
Fix interface inheritance for PHP 5.3.0 - 5.3.8
2015-10-02 15:43:01 +02:00
3099dcf617 Maintain compatibility for PHP 5.3.0 - 5.3.8
Interface inheritance is not possible before PHP 5.3.9. That is an
artefact of PHP bug 43200 (https://bugs.php.net/43200).

Since the composer.json states that the PHP versions >= 5.3.0 are
supported, we have to maintain compatibility with PHP 5.3.X.

Fixes: #7

Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2015-10-02 15:34:34 +02:00
Jacob Kiers
d2b3281815 Release 1.0.11
This release fixes a little bug in the exception that is thrown when an
invalid token is encountered.

Reported and fixed by @elieux.

Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-07-16 16:06:29 +02:00
999a007b3b Merge pull request #6 from elieux/master-fix1
Fix variable name when creating an "invalid token" exception
2015-07-16 16:04:50 +02:00
David Macek
3ef8e25bdb Fix variable name when creating an "invalid token" exception 2015-07-16 15:53:27 +02:00
4f352302a1 Made version parameter private (by @vimishor).
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-02-21 18:39:51 +01:00
Alexandru G
cc7992f2d1 oauth_version parameter should be optional 2014-02-17 15:43:13 +02:00
5616fa0756 Updated CONTRIBUTORS.md and started a change log.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2013-11-19 21:24:12 +01:00
f8ffcd6f87 Added tests for new required 'oauth_consumer_key'.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2013-11-19 21:21:41 +01:00
e4e8bc2f90 Merge remote-tracking branch 'vb/master' 2013-11-19 21:03:00 +01:00
victorbjelkholm
4011b3674d Throwing OAuthException without oauth_consumer_key 2013-11-19 20:58:34 +01:00
victorbjelkholm
fdb6c2df49 Update travis.yml 2013-11-19 20:57:18 +01:00
victorbjelkholm
da8c3c46c5 Remove parameter should be passed reference 2013-11-19 20:54:56 +01:00
victorbjelkholm
cec7f31cda Change colors=false to colors=true 2013-11-19 20:54:56 +01:00
ca5c3596dc Added .gitattributes
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2013-08-15 19:59:33 +02:00
b3d4f9b6bc Added CONTRIBUTORS.md file.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2013-06-06 05:58:53 +02:00
Alexandru G
087cb1278f Because $token refs an object, this statement will always be true. Therefore an empty oauth_token param will be added to each request, wich will break Bitbucket authorization process.
To fix this, we need to check if token key is empty and ignore it.
2013-06-06 05:58:53 +02:00
10 changed files with 69 additions and 45 deletions

14
.gitattributes vendored Normal file
View File

@@ -0,0 +1,14 @@
# Text files.
*.ini text
*.json text
*.md text
*.php text diff=php
*.phtml text diff=html
*.xml text
# Binary files.
*.alaw binary
*.gif binary
*.phar binary
*.png binary
*.wav binary

View File

@@ -1,14 +1,15 @@
sudo: false
language: php
php:
- 5.3
- 5.4
- 5.5
matrix:
allow_failures:
- php: 5.5
- 5.6
- 7
- hhvm
before_script:
- composer selfupdate --quiet
- composer install --dev
- composer install --prefer-dist
- vendor/phpunit/phpunit/composer/bin/phpunit

10
CHANGELOG.md Normal file
View File

@@ -0,0 +1,10 @@
Version 1.0.10 (2014-02-21)
* Made version parameter optional (@vimishor)
Version 1.0.9 (2013-11-19)
* Merged changes by @VictorBjelkholm. This results in a BC break:
Request\Request now requires the 'oauth_consumer_key' as a parameter
in the contructor.

11
CONTRIBUTORS.md Normal file
View File

@@ -0,0 +1,11 @@
This project has had multiple authors. In this file, I will try to credit
each of them. If you are not listed for some reason, please ask.
Andy Smith authored the original code (http://oauth.googlecode.com/svn/code/php/).
* Alexandre Eher (@EHER)
* Gary Jones (@GaryJones)
* Jacob Kiers (@jacobkiers)
* Alexandru G. (@vimishor)
* Victor Bjelkholm (@VictorBjelkholm)
* David Macek (@elieux)

View File

@@ -2,7 +2,7 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"

View File

@@ -68,6 +68,10 @@ class Request implements RequestInterface
*/
public function __construct($http_method, $http_url, array $parameters = null)
{
if(!isset($parameters['oauth_consumer_key'])) {
throw new OAuthException('You need a OAuth consumer key to proceed');
}
$parameters = ($parameters) ? $parameters : array();
$this->parameters = array_merge(Util::parseParameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
$this->http_method = $http_method;
@@ -153,11 +157,10 @@ public static function fromConsumerAndToken(
) {
$parameters = ($parameters) ? $parameters : array();
$defaults = array(
'oauth_version' => Request::$version,
'oauth_nonce' => Request::generateNonce(),
'oauth_timestamp' => Request::generateTimestamp(),
'oauth_consumer_key' => $consumer->getKey());
if ($token) {
if ($token->getKey()) {
$defaults['oauth_token'] = $token->getKey();
}

View File

@@ -89,7 +89,7 @@ public function addSignatureMethod(SignatureMethodInterface $signature_method)
*
* @return JacobKiers\OAuth\Token\TokenInterface
*/
public function fetchRequestToken(RequestInterface &$request)
public function fetchRequestToken(RequestInterface $request)
{
$this->getVersion($request);
@@ -115,7 +115,7 @@ public function fetchRequestToken(RequestInterface &$request)
*
* @return JacobKiers\OAuth\Token\TokenInterface
*/
public function fetchAccessToken(RequestInterface &$request)
public function fetchAccessToken(RequestInterface $request)
{
$this->getVersion($request);
@@ -139,7 +139,7 @@ public function fetchAccessToken(RequestInterface &$request)
*
* @return array Consumer and Token
*/
public function verifyRequest(RequestInterface &$request)
public function verifyRequest(RequestInterface $request)
{
$this->getVersion($request);
$consumer = $this->getConsumer($request);
@@ -159,7 +159,7 @@ public function verifyRequest(RequestInterface &$request)
*
* @throws JacobKiers\OAuth\OAuthException
*/
private function getVersion(RequestInterface &$request)
private function getVersion(RequestInterface $request)
{
$version = $request->getOAuthVersion();
if (!$version) {
@@ -243,7 +243,7 @@ private function getToken(RequestInterface $request, ConsumerInterface $consumer
$token = $this->data_store->lookupToken($consumer, $token_type, $token_key);
if (!$token) {
throw new OAuthException("Invalid $token_type token: $token_field");
throw new OAuthException("Invalid $token_type token: $token_key");
}
return $token;
}

View File

@@ -49,7 +49,7 @@ public function getName()
* Either way should return a string representation of the certificate
*
*/
abstract protected function fetchPublicCert(&$request);
abstract protected function fetchPublicCert($request);
/**
* Up to the SP to implement this lookup of keys. Possible ideas are:
@@ -57,7 +57,7 @@ abstract protected function fetchPublicCert(&$request);
*
* Either way should return a string representation of the certificate
*/
abstract protected function fetchPrivateCert(&$request);
abstract protected function fetchPrivateCert($request);
/**
* Build up the signature.

View File

@@ -27,28 +27,6 @@
*/
abstract class SignatureMethod implements SignatureMethodInterface
{
/**
* Return the name of the Signature Method (ie HMAC-SHA1).
*
* @return string
*/
abstract public function getName();
/**
* Build up the signature.
*
* NOTE: The output of this function MUST NOT be urlencoded.
* the encoding is handled in OAuthRequest when the final
* request is serialized.
*
* @param JacobKiers\OAuth\Request\RequestInterface $request
* @param JacobKiers\OAuth\Consumer\ConsumerInterface $consumer
* @param JacobKiers\OAuth\Token\TokenInterface $token
*
* @return string
*/
abstract public function buildSignature(RequestInterface $request, ConsumerInterface $consumer, TokenInterface $token = null);
/**
* Get the signature key, made up of consumer and optionally token shared secrets.
*

View File

@@ -10,27 +10,34 @@ public function tearDown()
m::close();
}
/**
* @expectedException \JacobKiers\OAuth\OAuthException
*/
public function testRequestThrowsExceptionWhenNoOAuthConsumerKeyIsPresent()
{
$request = new Request('POST', 'http://example.com', array());
}
public function testHttpMethodCanBeNormalized()
{
$request = new Request('foo', 'bar');
$request = new Request('foo', 'bar', array('oauth_consumer_key' => 'bar'));
$this->assertEquals('FOO', $request->getNormalizedHttpMethod());
}
public function testHttpUrlCanBeNormalized()
{
$request = new Request('foo', 'bar');
$request = new Request('foo', 'bar', array('oauth_consumer_key' => 'bar'));
$this->assertEquals('http://bar', $request->getNormalizedHttpUrl());
$request = new Request('foo', 'example.com:80');
$request = new Request('foo', 'example.com:80', array('oauth_consumer_key' => 'bar'));
$this->assertEquals('http://example.com', $request->getNormalizedHttpUrl());
$request = new Request('foo', 'example.com:81');
$request = new Request('foo', 'example.com:81', array('oauth_consumer_key' => 'bar'));
$this->assertEquals('http://example.com:81', $request->getNormalizedHttpUrl());
$request = new Request('foo', 'https://example.com');
$request = new Request('foo', 'https://example.com', array('oauth_consumer_key' => 'bar'));
$this->assertEquals('https://example.com', $request->getNormalizedHttpUrl());
$request = new Request('foo', 'https://example.com:443');
$request = new Request('foo', 'https://example.com:443', array('oauth_consumer_key' => 'bar'));
$this->assertEquals('https://example.com', $request->getNormalizedHttpUrl());
$request = new Request('foo', 'http://example.com/foobar');
$request = new Request('foo', 'http://example.com/foobar', array('oauth_consumer_key' => 'bar'));
$this->assertEquals('http://example.com/foobar', $request->getNormalizedHttpUrl());
$request = new Request('foo', 'example.org:80/foobar');
$request = new Request('foo', 'example.org:80/foobar', array('oauth_consumer_key' => 'bar'));
$this->assertEquals('http://example.org/foobar', $request->getNormalizedHttpUrl());
}
}