Compare commits

...

22 Commits
0.2 ... 0.2.3

Author SHA1 Message Date
Alex Bilbie
5b870a84f8 Merge branch 'release/0.2.3' 2012-09-19 19:54:20 +01:00
Alex Bilbie
7e009a2d02 Version number bump + email change
Signed-off-by: Alex Bilbie <alex@alexbilbie.com>
2012-09-19 19:54:11 +01:00
Alex Bilbie
602bc85121 Merge branch 'hotfix/auth-exceptions' into develop 2012-09-19 19:53:16 +01:00
Alex Bilbie
e567866a01 Merge branch 'hotfix/auth-exceptions' 2012-09-19 19:53:05 +01:00
Alex Bilbie
3c2720ece4 Renamed exceptions
Signed-off-by: Alex Bilbie <alex@alexbilbie.com>
2012-09-19 19:52:52 +01:00
Alex Bilbie
1440a5e46c Added a .gitattributes file
Signed-off-by: Alex Bilbie <alex@alexbilbie.com>
2012-09-19 19:48:32 +01:00
Alex Bilbie
0db10063ac Merge branch 'refs/heads/master' into develop 2012-09-19 19:34:17 +01:00
Alex Bilbie
9844613b2d Fixed test checks
Signed-off-by: Alex Bilbie <alex@alexbilbie.com>
2012-09-19 19:34:05 +01:00
Alex Bilbie
ed2cabc5b6 Merge branch 'master' of github.com:lncd/OAuth2
Conflicts:
	composer.json

Signed-off-by: Alex Bilbie <alex@alexbilbie.com>
2012-09-19 19:32:31 +01:00
Alex Bilbie
926034c824 Pulled latest changes 2012-09-19 19:30:35 +01:00
Alex Bilbie
e965bfdeb5 Merge branch 'release/0.2.2' into develop 2012-09-19 19:29:27 +01:00
Alex Bilbie
085f849855 Merge branch 'release/0.2.2' 2012-09-19 19:29:18 +01:00
Alex Bilbie
6ea2f6480d version number bump 2012-09-19 19:29:14 +01:00
Alex Bilbie
f75fef179a Merge branch 'hotfix/resource-fixes' into develop 2012-09-19 19:27:58 +01:00
Alex Bilbie
a6cfd40b0f Merge branch 'hotfix/resource-fixes' 2012-09-19 19:27:32 +01:00
Alex Bilbie
3f3b987fb1 Check responses from the database are valid 2012-09-19 19:27:04 +01:00
Alex Bilbie
bdbf9072f6 Update README.md 2012-09-07 12:59:41 +02:00
Alex Bilbie
248b09641d Merge branch 'hotfix/0.2.1' into develop 2012-08-28 12:31:36 +01:00
Alex Bilbie
0af98224dd Merge branch 'hotfix/0.2.1' 2012-08-28 12:31:07 +01:00
Alex Bilbie
88185320a8 Version bump 2012-08-28 12:30:58 +01:00
Alex Bilbie
a1e5fdddda Bug fix 2012-08-28 12:30:51 +01:00
Alex Bilbie
58d0a988a9 Merge branch 'release/0.2' into develop 2012-08-27 16:05:50 +01:00
7 changed files with 77 additions and 47 deletions

4
.gitattributes vendored Normal file
View File

@@ -0,0 +1,4 @@
tests/ export-ignore
phpunit.xml export-ignore
build.xml export-ignore
test export-ignore

View File

@@ -38,6 +38,10 @@ The resource server allows you to secure your API endpoints by checking for a va
* Support for [JSON web tokens](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-json-web-token/). * Support for [JSON web tokens](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-json-web-token/).
* Support for [SAML assertions](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-saml2-bearer/). * Support for [SAML assertions](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-saml2-bearer/).
### Client support
* Merge in https://github.com/philsturgeon/codeigniter-oauth2
--- ---
This code will be developed as part of the [Linkey](http://linkey.blogs.lincoln.ac.uk) project which has been funded by [JISC](http://jisc.ac.uk) under the Access and Identity Management programme. This code will be developed as part of the [Linkey](http://linkey.blogs.lincoln.ac.uk) project which has been funded by [JISC](http://jisc.ac.uk) under the Access and Identity Management programme.

View File

@@ -1,7 +1,7 @@
{ {
"name": "lncd/Oauth2", "name": "lncd/Oauth2",
"description": "OAuth 2.0 Framework", "description": "OAuth 2.0 Framework",
"version": "0.2", "version": "0.2.3",
"homepage": "https://github.com/lncd/OAuth2", "homepage": "https://github.com/lncd/OAuth2",
"license": "MIT", "license": "MIT",
"require": { "require": {
@@ -27,7 +27,7 @@
"authors": [ "authors": [
{ {
"name": "Alex Bilbie", "name": "Alex Bilbie",
"email": "oauth2server@alexbilbie.com", "email": "oauth2@alexbilbie.com",
"homepage": "http://www.httpster.org", "homepage": "http://www.httpster.org",
"role": "Developer" "role": "Developer"
} }

View File

@@ -2,17 +2,17 @@
namespace Oauth2\Authentication; namespace Oauth2\Authentication;
class OAuthServerClientException extends \Exception class ClientException extends \Exception
{ {
} }
class OAuthServerUserException extends \Exception class UserException extends \Exception
{ {
} }
class OAuthServerException extends \Exception class ServerException extends \Exception
{ {
} }
@@ -127,7 +127,7 @@ class Server
// Client ID // Client ID
if ( ! isset($authParams['client_id']) && ! isset($_GET['client_id'])) { if ( ! isset($authParams['client_id']) && ! isset($_GET['client_id'])) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_request'], 'client_id'), 0); throw new ClientException(sprintf($this->errors['invalid_request'], 'client_id'), 0);
} else { } else {
@@ -138,7 +138,7 @@ class Server
// Redirect URI // Redirect URI
if ( ! isset($authParams['redirect_uri']) && ! isset($_GET['redirect_uri'])) { if ( ! isset($authParams['redirect_uri']) && ! isset($_GET['redirect_uri'])) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_request'], 'redirect_uri'), 0); throw new ClientException(sprintf($this->errors['invalid_request'], 'redirect_uri'), 0);
} else { } else {
@@ -151,13 +151,13 @@ class Server
if ($clientDetails === false) { if ($clientDetails === false) {
throw new OAuthServerClientException($this->errors['invalid_client'], 8); throw new ClientException($this->errors['invalid_client'], 8);
} }
// Response type // Response type
if ( ! isset($authParams['response_type']) && ! isset($_GET['response_type'])) { if ( ! isset($authParams['response_type']) && ! isset($_GET['response_type'])) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_request'], 'response_type'), 0); throw new ClientException(sprintf($this->errors['invalid_request'], 'response_type'), 0);
} else { } else {
@@ -166,7 +166,7 @@ class Server
// Ensure response type is one that is recognised // Ensure response type is one that is recognised
if ( ! in_array($params['response_type'], $this->_responseTypes)) { if ( ! in_array($params['response_type'], $this->_responseTypes)) {
throw new OAuthServerClientException($this->errors['unsupported_response_type'], 3); throw new ClientException($this->errors['unsupported_response_type'], 3);
} }
} }
@@ -189,7 +189,7 @@ class Server
if (count($scopes) === 0) { if (count($scopes) === 0) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_request'], 'scope'), 0); throw new ClientException(sprintf($this->errors['invalid_request'], 'scope'), 0);
} }
$params['scopes'] = array(); $params['scopes'] = array();
@@ -200,7 +200,7 @@ class Server
if ($scopeDetails === false) { if ($scopeDetails === false) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_scope'], $scope), 4); throw new ClientException(sprintf($this->errors['invalid_scope'], $scope), 4);
} }
@@ -325,7 +325,7 @@ class Server
if ( ! isset($authParams['grant_type']) && ! isset($_POST['grant_type'])) { if ( ! isset($authParams['grant_type']) && ! isset($_POST['grant_type'])) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_request'], 'grant_type'), 0); throw new ClientException(sprintf($this->errors['invalid_request'], 'grant_type'), 0);
} else { } else {
@@ -334,7 +334,7 @@ class Server
// Ensure grant type is one that is recognised // Ensure grant type is one that is recognised
if ( ! in_array($params['grant_type'], $this->_grantTypes)) { if ( ! in_array($params['grant_type'], $this->_grantTypes)) {
throw new OAuthServerClientException($this->errors['unsupported_grant_type'], 7); throw new ClientException($this->errors['unsupported_grant_type'], 7);
} }
} }
@@ -350,7 +350,7 @@ class Server
case 'password': // Resource owner password credentials grant case 'password': // Resource owner password credentials grant
case 'client_credentials': // Client credentials grant case 'client_credentials': // Client credentials grant
default: // Unsupported default: // Unsupported
throw new OAuthServerException($this->errors['server_error'] . 'Tried to process an unsuppported grant type.', 5); throw new ServerException($this->errors['server_error'] . 'Tried to process an unsuppported grant type.', 5);
break; break;
} }
} }
@@ -370,7 +370,7 @@ class Server
// Client ID // Client ID
if ( ! isset($authParams['client_id']) && ! isset($_POST['client_id'])) { if ( ! isset($authParams['client_id']) && ! isset($_POST['client_id'])) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_request'], 'client_id'), 0); throw new ClientException(sprintf($this->errors['invalid_request'], 'client_id'), 0);
} else { } else {
@@ -381,7 +381,7 @@ class Server
// Client secret // Client secret
if ( ! isset($authParams['client_secret']) && ! isset($_POST['client_secret'])) { if ( ! isset($authParams['client_secret']) && ! isset($_POST['client_secret'])) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_request'], 'client_secret'), 0); throw new ClientException(sprintf($this->errors['invalid_request'], 'client_secret'), 0);
} else { } else {
@@ -392,7 +392,7 @@ class Server
// Redirect URI // Redirect URI
if ( ! isset($authParams['redirect_uri']) && ! isset($_POST['redirect_uri'])) { if ( ! isset($authParams['redirect_uri']) && ! isset($_POST['redirect_uri'])) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_request'], 'redirect_uri'), 0); throw new ClientException(sprintf($this->errors['invalid_request'], 'redirect_uri'), 0);
} else { } else {
@@ -409,13 +409,13 @@ class Server
if ($clientDetails === false) { if ($clientDetails === false) {
throw new OAuthServerClientException($this->errors['invalid_client'], 8); throw new ClientException($this->errors['invalid_client'], 8);
} }
// The authorization code // The authorization code
if ( ! isset($authParams['code']) && ! isset($_POST['code'])) { if ( ! isset($authParams['code']) && ! isset($_POST['code'])) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_request'], 'code'), 0); throw new ClientException(sprintf($this->errors['invalid_request'], 'code'), 0);
} else { } else {
@@ -433,7 +433,7 @@ class Server
if ( ! $session) { if ( ! $session) {
throw new OAuthServerClientException(sprintf($this->errors['invalid_grant'], 'code'), 9); throw new ClientException(sprintf($this->errors['invalid_grant'], 'code'), 9);
} else { } else {
@@ -500,11 +500,11 @@ class Server
private function _dbCall() private function _dbCall()
{ {
if ($this->_db === null) { if ($this->_db === null) {
throw new OAuthServerException('No registered database abstractor'); throw new ServerException('No registered database abstractor');
} }
if ( ! $this->_db instanceof Database) { if ( ! $this->_db instanceof Database) {
throw new OAuthServerException('Registered database abstractor is not an instance of Oauth2\Authentication\Database'); throw new ServerException('Registered database abstractor is not an instance of Oauth2\Authentication\Database');
} }
$args = func_get_args(); $args = func_get_args();

View File

@@ -2,7 +2,12 @@
namespace Oauth2\Resource; namespace Oauth2\Resource;
class OAuthResourceServerException extends \Exception class ServerException extends \Exception
{
}
class ClientException extends \Exception
{ {
} }
@@ -56,7 +61,9 @@ class Server
*/ */
public $errors = array( public $errors = array(
'missing_access_token' => 'An access token was not presented with the request', 'missing_access_token' => 'An access token was not presented with the request',
'invalid_access_token' => 'The access token is not registered with the resource server' 'invalid_access_token' => 'The access token is not registered with the resource server',
'missing_access_token_details' => 'The registered database abstractor did not return a valid access token details response',
'invalid_access_token_scopes' => 'The registered database abstractor did not return a valid access token scopes response',
); );
/** /**
@@ -114,6 +121,9 @@ class Server
{ {
$accessToken = null; $accessToken = null;
$_SERVER['REQUEST_METHOD'] = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null;
// Try and get the access token via an access_token or oauth_token parameter // Try and get the access token via an access_token or oauth_token parameter
switch ($_SERVER['REQUEST_METHOD']) switch ($_SERVER['REQUEST_METHOD'])
{ {
@@ -147,21 +157,33 @@ class Server
if ($result === false) { if ($result === false) {
throw new OAuthResourceServerException($this->errors['invalid_access_token']); throw new ClientException($this->errors['invalid_access_token']);
} else { } else {
if ( ! array_key_exists('id', $result) || ! array_key_exists('owner_id', $result) ||
! array_key_exists('owner_type', $result)) {
throw new ServerException($this->errors['missing_access_token_details']);
}
$this->_accessToken = $accessToken; $this->_accessToken = $accessToken;
$this->_type = $result['owner_type']; $this->_type = $result['owner_type'];
$this->_typeId = $result['owner_id']; $this->_typeId = $result['owner_id'];
// Get the scopes // Get the scopes
$this->_scopes = $this->_dbCall('sessionScopes', $result['id']); $scopes = $this->_dbCall('sessionScopes', $result['id']);
if ( ! is_array($scopes))
{
throw new ServerException($this->errors['invalid_access_token_scopes']);
}
$this->_scopes = $scopes;
} }
} else { } else {
throw new OAuthResourceServerException($this->errors['missing_access_token']); throw new ClientException($this->errors['missing_access_token']);
} }
} }
@@ -208,11 +230,11 @@ class Server
private function _dbCall() private function _dbCall()
{ {
if ($this->_db === null) { if ($this->_db === null) {
throw new OAuthResourceServerException('No registered database abstractor'); throw new ServerException('No registered database abstractor');
} }
if ( ! $this->_db instanceof Database) { if ( ! $this->_db instanceof Database) {
throw new OAuthResourceServerException('Registered database abstractor is not an instance of Oauth2\Resource\Database'); throw new ServerException('The registered database abstractor is not an instance of Oauth2\Resource\Database');
} }
$args = func_get_args(); $args = func_get_args();

View File

@@ -90,7 +90,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_checkClientAuthoriseParams_missingClientId() function test_checkClientAuthoriseParams_missingClientId()
@@ -99,7 +99,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_checkClientAuthoriseParams_missingRedirectUri() function test_checkClientAuthoriseParams_missingRedirectUri()
@@ -110,7 +110,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_checkClientAuthoriseParams_missingResponseType() function test_checkClientAuthoriseParams_missingResponseType()
@@ -122,7 +122,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_checkClientAuthoriseParams_missingScopes() function test_checkClientAuthoriseParams_missingScopes()
@@ -136,7 +136,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 4 * @expectedExceptionCode 4
*/ */
function test_checkClientAuthoriseParams_invalidScopes() function test_checkClientAuthoriseParams_invalidScopes()
@@ -247,7 +247,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_issueAccessToken_missingGrantType() function test_issueAccessToken_missingGrantType()
@@ -256,7 +256,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 7 * @expectedExceptionCode 7
*/ */
function test_issueAccessToken_unsupportedGrantType() function test_issueAccessToken_unsupportedGrantType()
@@ -267,7 +267,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_completeAuthCodeGrant_missingClientId() function test_completeAuthCodeGrant_missingClientId()
@@ -280,7 +280,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_completeAuthCodeGrant_missingClientSecret() function test_completeAuthCodeGrant_missingClientSecret()
@@ -295,7 +295,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_completeAuthCodeGrant_missingRedirectUri() function test_completeAuthCodeGrant_missingRedirectUri()
@@ -311,7 +311,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 8 * @expectedExceptionCode 8
*/ */
function test_completeAuthCodeGrant_invalidClient() function test_completeAuthCodeGrant_invalidClient()
@@ -328,7 +328,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_completeAuthCodeGrant_missingCode() function test_completeAuthCodeGrant_missingCode()
@@ -345,7 +345,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 9 * @expectedExceptionCode 9
*/ */
function test_completeAuthCodeGrant_invalidCode() function test_completeAuthCodeGrant_invalidCode()
@@ -363,7 +363,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerException * @expectedException Oauth2\Authentication\ServerException
* @expectedExceptionMessage No registered database abstractor * @expectedExceptionMessage No registered database abstractor
*/ */
function test_noRegisteredDatabaseAbstractor() function test_noRegisteredDatabaseAbstractor()
@@ -380,7 +380,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException Oauth2\Authentication\OAuthServerException * @expectedException Oauth2\Authentication\ServerException
* @expectedExceptionMessage Registered database abstractor is not an instance of Oauth2\Authentication\Database * @expectedExceptionMessage Registered database abstractor is not an instance of Oauth2\Authentication\Database
*/ */
function test_invalidRegisteredDatabaseAbstractor() function test_invalidRegisteredDatabaseAbstractor()

View File

@@ -72,7 +72,7 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException \Oauth2\Resource\OAuthResourceServerException * @expectedException \Oauth2\Resource\ClientException
* @expectedExceptionMessage An access token was not presented with the request * @expectedExceptionMessage An access token was not presented with the request
*/ */
function test_init_missingToken() function test_init_missingToken()
@@ -81,7 +81,7 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException \Oauth2\Resource\OAuthResourceServerException * @expectedException \Oauth2\Resource\ClientException
* @expectedExceptionMessage The access token is not registered with the resource server * @expectedExceptionMessage The access token is not registered with the resource server
*/ */
function test_init_wrongToken() function test_init_wrongToken()