Compare commits

...

17 Commits
3.2.1 ... 3.2.4

Author SHA1 Message Date
Alex Bilbie
13cd0cacdf Merge pull request #204 from ushahidi/missing-token-message
Add a new "missing_token" exception message to Resource server
2014-09-08 22:01:33 +01:00
Woody Gilk
f03e4a9e37 Add a new "missing_token" exception message to Resource server 2014-08-26 11:42:41 -05:00
Alex Bilbie
da92410ecb Merge pull request #196 from barryvdh/patch-1
Remove links to wiki
2014-08-13 08:29:34 +02:00
Alex Bilbie
23303905a8 Merge pull request #197 from GrahamCampbell/patch-1
Update composer.json
2014-08-10 11:15:18 +01:00
Graham Campbell
0b8e69f0d0 Update composer.json 2014-08-10 11:11:15 +01:00
Barry vd. Heuvel
a448f2167b Remove links to wiki
They don't work anymore. Not sure where they went?
2014-08-08 10:57:30 +02:00
Alex Bilbie
2f14f6b391 Version bump 2014-07-23 16:13:50 +01:00
Alex Bilbie
94369abd60 Merge branch 'release/3.2.2'
Conflicts:
	composer.json
2014-07-23 16:10:02 +01:00
Alex Bilbie
45edac4216 Version bump 2014-07-23 16:08:50 +01:00
Alex Bilbie
5bdfc9908a Updated changelog 2014-07-23 16:08:33 +01:00
Alex Bilbie
1890d71838 Merge branch 'develop' of github.com:thephpleague/oauth2-server into develop 2014-07-23 16:05:42 +01:00
Alex Bilbie
00d5fb5834 Merge pull request #188 from ushahidi/fix-http-headers-util-request
Fix Resource server Request HTTP header access
2014-07-23 15:58:24 +01:00
Robbie Mackay
49b776c495 In Resource::getExceptionHttpHeaders() use Request::BuildFromGlobals 2014-07-23 07:48:05 -07:00
Woody Gilk
31e03c2d36 Fix broken http header extraction in Util\Request 2014-07-23 07:47:29 -07:00
Alex Bilbie
6f85bcbbf1 Merge branch 'develop' of github.com:thephpleague/oauth2-server into develop 2014-07-22 11:45:54 +01:00
Phil Sturgeon
7771bc04ec Merge pull request #186 from ushahidi/resource-server-correct-http-error
Send HTTP 401 for invalid_token, rather than insufficient_scope
2014-07-15 15:39:28 +01:00
Woody Gilk
f34dd4a0cb 401 status is for invalid_token, not insufficient_scope 2014-07-11 11:59:18 -05:00
6 changed files with 26 additions and 28 deletions

View File

@@ -1,5 +1,9 @@
# Changelog # Changelog
## 3.2.2 (released 2014-07-23)
* Fix Resource server Request HTTP header access (Issue #188)
## 3.2 (released 2014-04-16) ## 3.2 (released 2014-04-16)
* Added the ability to change the algorithm that is used to generate the token strings (Issue #151) * Added the ability to change the algorithm that is used to generate the token strings (Issue #151)

View File

@@ -42,27 +42,13 @@ The authorization server is a flexible class and the following core specificatio
* client credentials ([section 2.3.1](http://tools.ietf.org/html/rfc6749#section-2.3.1)) * client credentials ([section 2.3.1](http://tools.ietf.org/html/rfc6749#section-2.3.1))
* password (user credentials) ([section 4.3](http://tools.ietf.org/html/rfc6749#section-4.3)) * password (user credentials) ([section 4.3](http://tools.ietf.org/html/rfc6749#section-4.3))
An [overview of the different OAuth 2.0 grants](https://github.com/thephpleague/oauth2-server/wiki/Which-OAuth-2.0-grant-should-I-use%3F) can be found in the [wiki].
### Resource Server ### Resource Server
The resource server allows you to secure your API endpoints by checking for a valid OAuth access token in the request and ensuring the token has the correct scope(s) (i.e. permissions) to access resources. The resource server allows you to secure your API endpoints by checking for a valid OAuth access token in the request and ensuring the token has the correct scope(s) (i.e. permissions) to access resources.
### Custom grants ### Custom grants
Custom grants can be created easily by implementing an interface. Check out the [custom grant guide](https://github.com/thephpleague/oauth2-server/wiki/Creating-custom-grants). Custom grants can be created easily by implementing an interface.
## Tutorials and Documentation
* **[Wiki]** - The wiki has lots of guides on how to use this library.
* **[Developing an OAuth-2.0 Authorization Server]** - A simple tutorial on how to use the authorization server.
* **[Securing your API with OAuth 2.0]** - A simple tutorial on how to use the resource server to secure an API server.
[Wiki]: https://github.com/thephpleague/oauth2-server/wiki
[Securing your API with OAuth 2.0]: https://github.com/thephpleague/oauth2-server/wiki/Securing-your-API-with-OAuth-2.0
[Developing an OAuth-2.0 Authorization Server]: https://github.com/thephpleague/oauth2-server/wiki/Developing-an-OAuth-2.0-authorization-server
## Changelog ## Changelog

View File

@@ -6,7 +6,7 @@
"php": ">=5.4.0" "php": ">=5.4.0"
}, },
"require-dev": { "require-dev": {
"mockery/mockery": ">=0.7.2", "mockery/mockery": "~0.8",
"league/phpunit-coverage-listener": "~1.0" "league/phpunit-coverage-listener": "~1.0"
}, },
"repositories": [ "repositories": [
@@ -43,7 +43,9 @@
"League\\OAuth2\\Server": "src/" "League\\OAuth2\\Server": "src/"
} }
}, },
"suggest": { "extra": {
"branch-alias": {
"dev-master": "3.2.x-dev"
}
} }
} }

View File

@@ -84,6 +84,7 @@ class Resource
0 => 'invalid_request', 0 => 'invalid_request',
1 => 'invalid_token', 1 => 'invalid_token',
2 => 'insufficient_scope', 2 => 'insufficient_scope',
3 => 'missing_token',
); );
/** /**
@@ -94,6 +95,7 @@ class Resource
'invalid_request' => 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "%s" parameter.', 'invalid_request' => 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "%s" parameter.',
'invalid_token' => 'The access token provided is expired, revoked, malformed, or invalid for other reasons.', 'invalid_token' => 'The access token provided is expired, revoked, malformed, or invalid for other reasons.',
'insufficient_scope' => 'The request requires higher privileges than provided by the access token. Required scopes are: %s.', 'insufficient_scope' => 'The request requires higher privileges than provided by the access token. Required scopes are: %s.',
'missing_token' => 'The request is missing an access token in either the Authorization header or the %s request parameter.',
); );
/** /**
@@ -109,6 +111,7 @@ class Resource
'invalid_request' => 400, 'invalid_request' => 400,
'invalid_token' => 401, 'invalid_token' => 401,
'insufficient_scope' => 403, 'insufficient_scope' => 403,
'missing_token' => 400,
); );
/** /**
@@ -163,9 +166,9 @@ class Resource
// include the "WWW-Authenticate" response header field // include the "WWW-Authenticate" response header field
// matching the authentication scheme used by the client. // matching the authentication scheme used by the client.
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
if ($error === 'insufficient_scope') { if ($error === 'invalid_token') {
$authScheme = null; $authScheme = null;
$request = new Request(); $request = Request::buildFromGlobals();
if ($request->server('PHP_AUTH_USER') !== null) { if ($request->server('PHP_AUTH_USER') !== null) {
$authScheme = 'Basic'; $authScheme = 'Basic';
} else { } else {
@@ -387,7 +390,7 @@ class Resource
} }
if (empty($accessToken)) { if (empty($accessToken)) {
throw new Exception\MissingAccessTokenException(self::$exceptionMessages['invalid_request'], 0); throw new Exception\MissingAccessTokenException(sprintf(self::$exceptionMessages['missing_token'], $this->tokenKey), 3);
} }
return $accessToken; return $accessToken;

View File

@@ -76,15 +76,18 @@ class Request implements RequestInterface
protected function readHeaders() protected function readHeaders()
{ {
if (function_exists('getallheaders')) { if (function_exists('apache_request_headers')) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$headers = getallheaders(); $headers = apache_request_headers();
} elseif (function_exists('http_get_request_headers')) {
$headers = http_get_request_headers();
} else { } else {
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
$headers = array(); $headers = array();
foreach ($this->server() as $name => $value) { foreach ($this->server() as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') { if (substr($name, 0, 5) == 'HTTP_') {
$name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); // HTTP_FOO_BAR becomes FOO-BAR
$name = str_replace(array('HTTP_', '_'), array('', '-'), $name);
$headers[$name] = $value; $headers[$name] = $value;
} }
} }

View File

@@ -38,8 +38,8 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase
public function test_getExceptionHttpHeaders() public function test_getExceptionHttpHeaders()
{ {
$this->assertEquals(array('HTTP/1.1 400 Bad Request'), League\OAuth2\Server\Resource::getExceptionHttpHeaders('invalid_request')); $this->assertEquals(array('HTTP/1.1 400 Bad Request'), League\OAuth2\Server\Resource::getExceptionHttpHeaders('invalid_request'));
$this->assertEquals(array('HTTP/1.1 401 Unauthorized'), League\OAuth2\Server\Resource::getExceptionHttpHeaders('invalid_token')); $this->assertContains('HTTP/1.1 401 Unauthorized', League\OAuth2\Server\Resource::getExceptionHttpHeaders('invalid_token'));
$this->assertContains('HTTP/1.1 403 Forbidden', League\OAuth2\Server\Resource::getExceptionHttpHeaders('insufficient_scope')); $this->assertEquals(array('HTTP/1.1 403 Forbidden'), League\OAuth2\Server\Resource::getExceptionHttpHeaders('insufficient_scope'));
} }
public function test_setRequest() public function test_setRequest()