Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Sephster 2017-11-13 23:52:36 +00:00
commit 7878cf9c13
No known key found for this signature in database
GPG Key ID: 815DE090877B53F3
21 changed files with 49 additions and 26 deletions

View File

@ -79,7 +79,10 @@ This package is released under the MIT License. See the bundled [LICENSE](https:
## Credits ## Credits
This code is principally developed and maintained by [Alex Bilbie](https://twitter.com/alexbilbie). This code is principally developed and maintained by [Andy Millington](https://twitter.com/Sephster), [Brian
Retterer](https://twitter.com/bretterer), and [Simon Hamp](https://twitter.com/simonhamp).
Between 2012 and 2017 this library was developed and maintained by [Alex Bilbie](https://alexbilbie.com/).
Special thanks to [all of these awesome contributors](https://github.com/thephpleague/oauth2-server/contributors). Special thanks to [all of these awesome contributors](https://github.com/thephpleague/oauth2-server/contributors).

View File

@ -13,7 +13,7 @@
"defuse/php-encryption": "^2.1" "defuse/php-encryption": "^2.1"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^4.8 || ^5.0", "phpunit/phpunit": "^4.8.38 || ^5.7.21",
"zendframework/zend-diactoros": "^1.0" "zendframework/zend-diactoros": "^1.0"
}, },
"repositories": [ "repositories": [

View File

@ -7,7 +7,8 @@
"lcobucci/jwt": "^3.1", "lcobucci/jwt": "^3.1",
"paragonie/random_compat": "^2.0", "paragonie/random_compat": "^2.0",
"psr/http-message": "^1.0", "psr/http-message": "^1.0",
"defuse/php-encryption": "^2.1" "defuse/php-encryption": "^2.1",
"zendframework/zend-diactoros": "^1.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@ -3,6 +3,7 @@
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */

View File

@ -1,9 +1,11 @@
<?php <?php
/** /**
* Public/private key encryption. * Public/private key encryption.
*
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
@ -24,6 +26,7 @@ trait CryptTrait
* @param string $unencryptedData * @param string $unencryptedData
* *
* @throws \LogicException * @throws \LogicException
*
* @return string * @return string
*/ */
protected function encrypt($unencryptedData) protected function encrypt($unencryptedData)
@ -41,6 +44,7 @@ trait CryptTrait
* @param string $encryptedData * @param string $encryptedData
* *
* @throws \LogicException * @throws \LogicException
*
* @return string * @return string
*/ */
protected function decrypt($encryptedData) protected function decrypt($encryptedData)

View File

@ -27,11 +27,18 @@ class ImplicitGrant extends AbstractAuthorizeGrant
private $accessTokenTTL; private $accessTokenTTL;
/** /**
* @param \DateInterval $accessTokenTTL * @var string
*/ */
public function __construct(\DateInterval $accessTokenTTL) private $queryDelimiter;
/**
* @param \DateInterval $accessTokenTTL
* @param string $queryDelimiter
*/
public function __construct(\DateInterval $accessTokenTTL, $queryDelimiter = '#')
{ {
$this->accessTokenTTL = $accessTokenTTL; $this->accessTokenTTL = $accessTokenTTL;
$this->queryDelimiter = $queryDelimiter;
} }
/** /**
@ -95,7 +102,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant
public function canRespondToAuthorizationRequest(ServerRequestInterface $request) public function canRespondToAuthorizationRequest(ServerRequestInterface $request)
{ {
return ( return (
array_key_exists('response_type', $request->getQueryParams()) isset($request->getQueryParams()['response_type'])
&& $request->getQueryParams()['response_type'] === 'token' && $request->getQueryParams()['response_type'] === 'token'
&& isset($request->getQueryParams()['client_id']) && isset($request->getQueryParams()['client_id'])
); );
@ -204,7 +211,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant
'expires_in' => $accessToken->getExpiryDateTime()->getTimestamp() - (new \DateTime())->getTimestamp(), 'expires_in' => $accessToken->getExpiryDateTime()->getTimestamp() - (new \DateTime())->getTimestamp(),
'state' => $authorizationRequest->getState(), 'state' => $authorizationRequest->getState(),
], ],
'#' $this->queryDelimiter
) )
); );

View File

@ -60,5 +60,4 @@ abstract class AbstractResponseType implements ResponseTypeInterface
{ {
$this->privateKey = $key; $this->privateKey = $key;
} }
} }

View File

@ -3,7 +3,6 @@
namespace LeagueTests; namespace LeagueTests;
use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\CryptKey;
use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\AuthCodeGrant; use League\OAuth2\Server\Grant\AuthCodeGrant;
use League\OAuth2\Server\Grant\ClientCredentialsGrant; use League\OAuth2\Server\Grant\ClientCredentialsGrant;
@ -21,11 +20,12 @@ use LeagueTests\Stubs\ScopeEntity;
use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\StubResponseType;
use LeagueTests\Stubs\UserEntity; use LeagueTests\Stubs\UserEntity;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
class AuthorizationServerTest extends \PHPUnit_Framework_TestCase class AuthorizationServerTest extends TestCase
{ {
const DEFAULT_SCOPE = 'basic'; const DEFAULT_SCOPE = 'basic';

View File

@ -3,8 +3,9 @@
namespace LeagueTests\Utils; namespace LeagueTests\Utils;
use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\CryptKey;
use PHPUnit\Framework\TestCase;
class CryptKeyTest extends \PHPUnit_Framework_TestCase class CryptKeyTest extends TestCase
{ {
/** /**
* @expectedException \LogicException * @expectedException \LogicException

View File

@ -2,10 +2,10 @@
namespace LeagueTests\Utils; namespace LeagueTests\Utils;
use League\OAuth2\Server\CryptKey;
use LeagueTests\Stubs\CryptTraitStub; use LeagueTests\Stubs\CryptTraitStub;
use PHPUnit\Framework\TestCase;
class CryptTraitTest extends \PHPUnit_Framework_TestCase class CryptTraitTest extends TestCase
{ {
/** /**
* @var \LeagueTests\Stubs\CryptTraitStub * @var \LeagueTests\Stubs\CryptTraitStub

View File

@ -3,7 +3,6 @@
namespace LeagueTests\Grant; namespace LeagueTests\Grant;
use League\Event\Emitter; use League\Event\Emitter;
use League\OAuth2\Server\CryptKey;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use League\OAuth2\Server\Entities\AuthCodeEntityInterface; use League\OAuth2\Server\Entities\AuthCodeEntityInterface;
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
@ -19,9 +18,10 @@ use LeagueTests\Stubs\AuthCodeEntity;
use LeagueTests\Stubs\ClientEntity; use LeagueTests\Stubs\ClientEntity;
use LeagueTests\Stubs\RefreshTokenEntity; use LeagueTests\Stubs\RefreshTokenEntity;
use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\ScopeEntity;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
class AbstractGrantTest extends \PHPUnit_Framework_TestCase class AbstractGrantTest extends TestCase
{ {
public function testGetSet() public function testGetSet()
{ {

View File

@ -2,7 +2,6 @@
namespace LeagueTests\Grant; namespace LeagueTests\Grant;
use League\OAuth2\Server\CryptKey;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\OAuthServerException;
@ -23,9 +22,10 @@ use LeagueTests\Stubs\RefreshTokenEntity;
use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\ScopeEntity;
use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\StubResponseType;
use LeagueTests\Stubs\UserEntity; use LeagueTests\Stubs\UserEntity;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase class AuthCodeGrantTest extends TestCase
{ {
const DEFAULT_SCOPE = 'basic'; const DEFAULT_SCOPE = 'basic';

View File

@ -11,9 +11,10 @@ use LeagueTests\Stubs\AccessTokenEntity;
use LeagueTests\Stubs\ClientEntity; use LeagueTests\Stubs\ClientEntity;
use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\ScopeEntity;
use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\StubResponseType;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase class ClientCredentialsGrantTest extends TestCase
{ {
const DEFAULT_SCOPE = 'basic'; const DEFAULT_SCOPE = 'basic';

View File

@ -18,9 +18,10 @@ use LeagueTests\Stubs\CryptTraitStub;
use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\ScopeEntity;
use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\StubResponseType;
use LeagueTests\Stubs\UserEntity; use LeagueTests\Stubs\UserEntity;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
class ImplicitGrantTest extends \PHPUnit_Framework_TestCase class ImplicitGrantTest extends TestCase
{ {
const DEFAULT_SCOPE = 'basic'; const DEFAULT_SCOPE = 'basic';

View File

@ -16,9 +16,10 @@ use LeagueTests\Stubs\RefreshTokenEntity;
use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\ScopeEntity;
use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\StubResponseType;
use LeagueTests\Stubs\UserEntity; use LeagueTests\Stubs\UserEntity;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
class PasswordGrantTest extends \PHPUnit_Framework_TestCase class PasswordGrantTest extends TestCase
{ {
const DEFAULT_SCOPE = 'basic'; const DEFAULT_SCOPE = 'basic';

View File

@ -16,9 +16,10 @@ use LeagueTests\Stubs\CryptTraitStub;
use LeagueTests\Stubs\RefreshTokenEntity; use LeagueTests\Stubs\RefreshTokenEntity;
use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\ScopeEntity;
use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\StubResponseType;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase class RefreshTokenGrantTest extends TestCase
{ {
/** /**
* @var CryptTraitStub * @var CryptTraitStub

View File

@ -13,10 +13,11 @@ use LeagueTests\Stubs\AccessTokenEntity;
use LeagueTests\Stubs\ClientEntity; use LeagueTests\Stubs\ClientEntity;
use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\ScopeEntity;
use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\StubResponseType;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
class AuthorizationServerMiddlewareTest extends \PHPUnit_Framework_TestCase class AuthorizationServerMiddlewareTest extends TestCase
{ {
const DEFAULT_SCOPE = 'basic'; const DEFAULT_SCOPE = 'basic';

View File

@ -8,10 +8,11 @@ use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\ResourceServer; use League\OAuth2\Server\ResourceServer;
use LeagueTests\Stubs\AccessTokenEntity; use LeagueTests\Stubs\AccessTokenEntity;
use LeagueTests\Stubs\ClientEntity; use LeagueTests\Stubs\ClientEntity;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
class ResourceServerMiddlewareTest extends \PHPUnit_Framework_TestCase class ResourceServerMiddlewareTest extends TestCase
{ {
public function testValidResponse() public function testValidResponse()
{ {

View File

@ -6,9 +6,10 @@ namespace LeagueTests;
use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\ResourceServer; use League\OAuth2\Server\ResourceServer;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
class ResourceServerTest extends \PHPUnit_Framework_TestCase class ResourceServerTest extends TestCase
{ {
public function testValidateAuthenticatedRequest() public function testValidateAuthenticatedRequest()
{ {

View File

@ -11,11 +11,12 @@ use LeagueTests\Stubs\AccessTokenEntity;
use LeagueTests\Stubs\ClientEntity; use LeagueTests\Stubs\ClientEntity;
use LeagueTests\Stubs\RefreshTokenEntity; use LeagueTests\Stubs\RefreshTokenEntity;
use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\ScopeEntity;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase class BearerResponseTypeTest extends TestCase
{ {
public function testGenerateHttpResponse() public function testGenerateHttpResponse()
{ {

View File

@ -2,7 +2,6 @@
namespace LeagueTests\Stubs; namespace LeagueTests\Stubs;
use League\OAuth2\Server\CryptKey;
use League\OAuth2\Server\CryptTrait; use League\OAuth2\Server\CryptTrait;
class CryptTraitStub class CryptTraitStub