11 Commits

Author SHA1 Message Date
Mauro Asprea
1249c00987 Add load balancer support using non-standard X-Forwarded headers 2014-10-15 20:34:46 +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
9 changed files with 59 additions and 22 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,13 +1,8 @@
language: php language: php
php: php:
- 5.3
- 5.4 - 5.4
- 5.5 - 5.5
matrix:
allow_failures:
- php: 5.5
before_script: before_script:
- composer selfupdate --quiet - composer selfupdate --quiet
- composer install --dev - composer install --dev

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.

View File

@@ -7,3 +7,4 @@ Andy Smith authored the original code (http://oauth.googlecode.com/svn/code/php/
* Gary Jones (@GaryJones) * Gary Jones (@GaryJones)
* Jacob Kiers (@jacobkiers) * Jacob Kiers (@jacobkiers)
* Alexandru G. (@vimishor) * Alexandru G. (@vimishor)
* Victor Bjelkholm (@VictorBjelkholm)

View File

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

View File

@@ -68,6 +68,10 @@ class Request implements RequestInterface
*/ */
public function __construct($http_method, $http_url, array $parameters = null) 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(); $parameters = ($parameters) ? $parameters : array();
$this->parameters = array_merge(Util::parseParameters(parse_url($http_url, PHP_URL_QUERY)), $parameters); $this->parameters = array_merge(Util::parseParameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
$this->http_method = $http_method; $this->http_method = $http_method;
@@ -89,10 +93,17 @@ public function __construct($http_method, $http_url, array $parameters = null)
public static function fromRequest($http_method = null, $http_url = null, $parameters = null) public static function fromRequest($http_method = null, $http_url = null, $parameters = null)
{ {
$scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') ? 'http' : 'https'; $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') ? 'http' : 'https';
$scheme = isset($_SERVER['HTTP_X_FORWARDED_PROTO'])
? $_SERVER['HTTP_X_FORWARDED_PROTO']
: $scheme;
$port = isset($_SERVER['HTTP_X_FORWARDED_PORT'])
? $_SERVER['HTTP_X_FORWARDED_PORT']
: $_SERVER['SERVER_PORT'];
$http_url = ($http_url) ? $http_url : $scheme . $http_url = ($http_url) ? $http_url : $scheme .
'://' . $_SERVER['HTTP_HOST'] . '://' . $_SERVER['HTTP_HOST'] .
':' . ':' .
$_SERVER['SERVER_PORT'] . $port .
$_SERVER['REQUEST_URI']; $_SERVER['REQUEST_URI'];
$http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD']; $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD'];
@@ -153,7 +164,6 @@ public static function fromConsumerAndToken(
) { ) {
$parameters = ($parameters) ? $parameters : array(); $parameters = ($parameters) ? $parameters : array();
$defaults = array( $defaults = array(
'oauth_version' => Request::$version,
'oauth_nonce' => Request::generateNonce(), 'oauth_nonce' => Request::generateNonce(),
'oauth_timestamp' => Request::generateTimestamp(), 'oauth_timestamp' => Request::generateTimestamp(),
'oauth_consumer_key' => $consumer->getKey()); 'oauth_consumer_key' => $consumer->getKey());

View File

@@ -89,7 +89,7 @@ public function addSignatureMethod(SignatureMethodInterface $signature_method)
* *
* @return JacobKiers\OAuth\Token\TokenInterface * @return JacobKiers\OAuth\Token\TokenInterface
*/ */
public function fetchRequestToken(RequestInterface &$request) public function fetchRequestToken(RequestInterface $request)
{ {
$this->getVersion($request); $this->getVersion($request);
@@ -115,7 +115,7 @@ public function fetchRequestToken(RequestInterface &$request)
* *
* @return JacobKiers\OAuth\Token\TokenInterface * @return JacobKiers\OAuth\Token\TokenInterface
*/ */
public function fetchAccessToken(RequestInterface &$request) public function fetchAccessToken(RequestInterface $request)
{ {
$this->getVersion($request); $this->getVersion($request);
@@ -139,7 +139,7 @@ public function fetchAccessToken(RequestInterface &$request)
* *
* @return array Consumer and Token * @return array Consumer and Token
*/ */
public function verifyRequest(RequestInterface &$request) public function verifyRequest(RequestInterface $request)
{ {
$this->getVersion($request); $this->getVersion($request);
$consumer = $this->getConsumer($request); $consumer = $this->getConsumer($request);
@@ -159,7 +159,7 @@ public function verifyRequest(RequestInterface &$request)
* *
* @throws JacobKiers\OAuth\OAuthException * @throws JacobKiers\OAuth\OAuthException
*/ */
private function getVersion(RequestInterface &$request) private function getVersion(RequestInterface $request)
{ {
$version = $request->getOAuthVersion(); $version = $request->getOAuthVersion();
if (!$version) { if (!$version) {

View File

@@ -49,7 +49,7 @@ public function getName()
* Either way should return a string representation of the certificate * 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: * 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 * Either way should return a string representation of the certificate
*/ */
abstract protected function fetchPrivateCert(&$request); abstract protected function fetchPrivateCert($request);
/** /**
* Build up the signature. * Build up the signature.

View File

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