diff --git a/src/AuthorizationValidators/BearerTokenValidator.php b/src/AuthorizationValidators/BearerTokenValidator.php index 5dab2203..3c550e19 100644 --- a/src/AuthorizationValidators/BearerTokenValidator.php +++ b/src/AuthorizationValidators/BearerTokenValidator.php @@ -43,7 +43,7 @@ class BearerTokenValidator implements AuthorizationValidatorInterface try { // Attempt to parse and validate the JWT $token = (new Parser())->parse($jwt); - if ($token->verify(new Sha256(), $this->publicKeyPath) === false) { + if ($token->verify(new Sha256(), $this->publicKey->getKeyPath()) === false) { throw OAuthServerException::accessDenied('Access token could not be verified'); } diff --git a/src/CryptKey.php b/src/CryptKey.php new file mode 100644 index 00000000..4ea05264 --- /dev/null +++ b/src/CryptKey.php @@ -0,0 +1,62 @@ + + * @copyright Copyright (c) Alex Bilbie + * @license http://mit-license.org/ + * + * @link https://github.com/thephpleague/oauth2-server + */ +namespace League\OAuth2\Server; + +class CryptKey +{ + /** + * @var string + */ + protected $keyPath; + + /** + * @var string + */ + protected $passPhrase; + + /** + * @param string $keyPath + * @param null|string $passPhrase + */ + public function __construct($keyPath, $passPhrase = null) + { + if (strpos($keyPath, 'file://') !== 0) { + $keyPath = 'file://' . $keyPath; + } + + if (!file_exists($keyPath) || !is_readable($keyPath)) { + throw new \LogicException(sprintf('Key path "%s" does not exist or is not readable', $keyPath)); + } + + $this->keyPath = $keyPath; + $this->passPhrase = $passPhrase; + } + + /** + * Retrieve key path. + * + * @return string + */ + public function getKeyPath() + { + return $this->keyPath; + } + + /** + * Retrieve key pass phrase. + * + * @return null|string + */ + public function getPassPhrase() + { + return $this->passPhrase; + } +} diff --git a/src/CryptTrait.php b/src/CryptTrait.php index 3c648b79..1075ea12 100644 --- a/src/CryptTrait.php +++ b/src/CryptTrait.php @@ -13,41 +13,33 @@ namespace League\OAuth2\Server; trait CryptTrait { /** - * @var string + * @var \League\OAuth2\Server\CryptKey */ - protected $privateKeyPath; + protected $privateKey; /** - * @var string + * @var \League\OAuth2\Server\CryptKey */ - protected $publicKeyPath; + protected $publicKey; /** * Set path to private key. * - * @param string $privateKeyPath + * @param \League\OAuth2\Server\CryptKey $privateKey */ - public function setPrivateKeyPath($privateKeyPath) + public function setPrivateKey(CryptKey $privateKey) { - if (strpos($privateKeyPath, 'file://') !== 0) { - $privateKeyPath = 'file://' . $privateKeyPath; - } - - $this->privateKeyPath = $privateKeyPath; + $this->privateKey = $privateKey; } /** * Set path to public key. * - * @param string $publicKeyPath + * @param \League\OAuth2\Server\CryptKey $publicKey */ - public function setPublicKeyPath($publicKeyPath) + public function setPublicKey(CryptKey $publicKey) { - if (strpos($publicKeyPath, 'file://') !== 0) { - $publicKeyPath = 'file://' . $publicKeyPath; - } - - $this->publicKeyPath = $publicKeyPath; + $this->publicKey = $publicKey; } /** @@ -59,10 +51,12 @@ trait CryptTrait */ protected function encrypt($unencryptedData) { - $privateKey = openssl_pkey_get_private($this->privateKeyPath); + $privateKey = openssl_pkey_get_private($this->privateKey->getKeyPath(), $this->privateKey->getPassPhrase()); $privateKeyDetails = @openssl_pkey_get_details($privateKey); if ($privateKeyDetails === null) { - throw new \LogicException(sprintf('Could not get details of private key: %s', $this->privateKeyPath)); + throw new \LogicException( + sprintf('Could not get details of private key: %s', $this->privateKey->getKeyPath()) + ); } $chunkSize = ceil($privateKeyDetails['bits'] / 8) - 11; @@ -78,7 +72,7 @@ trait CryptTrait } $output .= $encrypted; } - openssl_free_key($privateKey); + openssl_pkey_free($privateKey); return base64_encode($output); } @@ -94,10 +88,12 @@ trait CryptTrait */ protected function decrypt($encryptedData) { - $publicKey = openssl_pkey_get_public($this->publicKeyPath); + $publicKey = openssl_pkey_get_public($this->publicKey->getKeyPath()); $publicKeyDetails = @openssl_pkey_get_details($publicKey); if ($publicKeyDetails === null) { - throw new \LogicException(sprintf('Could not get details of public key: %s', $this->publicKeyPath)); + throw new \LogicException( + sprintf('Could not get details of public key: %s', $this->publicKey->getKeyPath()) + ); } $chunkSize = ceil($publicKeyDetails['bits'] / 8); @@ -115,7 +111,7 @@ trait CryptTrait } $output .= $decrypted; } - openssl_free_key($publicKey); + openssl_pkey_free($publicKey); return $output; } diff --git a/src/Entities/AccessTokenEntity.php b/src/Entities/AccessTokenEntity.php index 5b4b34a1..34ae167e 100644 --- a/src/Entities/AccessTokenEntity.php +++ b/src/Entities/AccessTokenEntity.php @@ -5,6 +5,7 @@ namespace League\OAuth2\Server\Entities; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Key; use Lcobucci\JWT\Signer\Rsa\Sha256; +use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Traits\EntityTrait; use League\OAuth2\Server\Entities\Traits\TokenEntityTrait; @@ -16,11 +17,11 @@ class AccessTokenEntity implements AccessTokenEntityInterface /** * Generate a JWT from the access token * - * @param string $privateKeyPath + * @param \League\OAuth2\Server\CryptKey $privateKey * * @return string */ - public function convertToJWT($privateKeyPath) + public function convertToJWT(CryptKey $privateKey) { return (new Builder()) ->setAudience($this->getClient()->getIdentifier()) @@ -30,7 +31,7 @@ class AccessTokenEntity implements AccessTokenEntityInterface ->setExpiration($this->getExpiryDateTime()->getTimestamp()) ->setSubject($this->getUserIdentifier()) ->set('scopes', $this->getScopes()) - ->sign(new Sha256(), new Key($privateKeyPath)) + ->sign(new Sha256(), new Key($privateKey->getKeyPath(), $privateKey->getPassPhrase())) ->getToken(); } } diff --git a/src/Entities/Interfaces/AccessTokenEntityInterface.php b/src/Entities/Interfaces/AccessTokenEntityInterface.php index 86ad1107..2b4c38a8 100644 --- a/src/Entities/Interfaces/AccessTokenEntityInterface.php +++ b/src/Entities/Interfaces/AccessTokenEntityInterface.php @@ -2,14 +2,16 @@ namespace League\OAuth2\Server\Entities\Interfaces; +use League\OAuth2\Server\CryptKey; + interface AccessTokenEntityInterface extends TokenInterface { /** * Generate a JWT from the access token * - * @param string $privateKeyPath + * @param \League\OAuth2\Server\CryptKey $privateKey * * @return string */ - public function convertToJWT($privateKeyPath); + public function convertToJWT(CryptKey $privateKey); } diff --git a/src/Grant/GrantTypeInterface.php b/src/Grant/GrantTypeInterface.php index cb60bf90..0e4ce62d 100644 --- a/src/Grant/GrantTypeInterface.php +++ b/src/Grant/GrantTypeInterface.php @@ -11,6 +11,7 @@ namespace League\OAuth2\Server\Grant; use League\Event\EmitterAwareInterface; +use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; @@ -89,14 +90,14 @@ interface GrantTypeInterface extends EmitterAwareInterface /** * Set the path to the private key. * - * @param string $privateKeyPath + * @param \League\OAuth2\Server\CryptKey $privateKey */ - public function setPrivateKeyPath($privateKeyPath); + public function setPrivateKey(CryptKey $privateKey); /** * Set the path to the public key. * - * @param string $publicKeyPath + * @param \League\OAuth2\Server\CryptKey $publicKey */ - public function setPublicKeyPath($publicKeyPath); + public function setPublicKey(CryptKey $publicKey); } diff --git a/src/Grant/ImplicitGrant.php b/src/Grant/ImplicitGrant.php index 11950a78..2fe4a455 100644 --- a/src/Grant/ImplicitGrant.php +++ b/src/Grant/ImplicitGrant.php @@ -197,7 +197,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant $scopes ); - $redirectPayload['access_token'] = (string) $accessToken->convertToJWT($this->privateKeyPath); + $redirectPayload['access_token'] = (string) $accessToken->convertToJWT($this->privateKey); $redirectPayload['token_type'] = 'bearer'; $redirectPayload['expires_in'] = time() - $accessToken->getExpiryDateTime()->getTimestamp(); diff --git a/src/ResponseTypes/BearerTokenResponse.php b/src/ResponseTypes/BearerTokenResponse.php index 17675b88..7a77c699 100644 --- a/src/ResponseTypes/BearerTokenResponse.php +++ b/src/ResponseTypes/BearerTokenResponse.php @@ -22,7 +22,7 @@ class BearerTokenResponse extends AbstractResponseType { $expireDateTime = $this->accessToken->getExpiryDateTime()->getTimestamp(); - $jwtAccessToken = $this->accessToken->convertToJWT($this->privateKeyPath); + $jwtAccessToken = $this->accessToken->convertToJWT($this->privateKey); $responseParams = [ 'token_type' => 'Bearer', diff --git a/src/Server.php b/src/Server.php index e77a344b..e5573026 100644 --- a/src/Server.php +++ b/src/Server.php @@ -32,20 +32,20 @@ class Server implements EmitterAwareInterface protected $grantTypeAccessTokenTTL = []; /** - * @var string + * @var \League\OAuth2\Server\CryptKey */ - protected $privateKeyPath; + protected $privateKey; + + /** + * @var \League\OAuth2\Server\CryptKey + */ + protected $publicKey; /** * @var ResponseTypeInterface */ protected $responseType; - /** - * @var string - */ - private $publicKeyPath; - /** * @var \League\OAuth2\Server\Repositories\ClientRepositoryInterface */ @@ -72,8 +72,8 @@ class Server implements EmitterAwareInterface * @param \League\OAuth2\Server\Repositories\ClientRepositoryInterface $clientRepository * @param \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface $accessTokenRepository * @param \League\OAuth2\Server\Repositories\ScopeRepositoryInterface $scopeRepository - * @param string $privateKeyPath - * @param string $publicKeyPath + * @param \League\OAuth2\Server\CryptKey|string $privateKey + * @param \League\OAuth2\Server\CryptKey|string $publicKey * @param null|\League\OAuth2\Server\ResponseTypes\ResponseTypeInterface $responseType * @param null|\League\OAuth2\Server\AuthorizationValidators\AuthorizationValidatorInterface $authorizationValidator */ @@ -81,16 +81,25 @@ class Server implements EmitterAwareInterface ClientRepositoryInterface $clientRepository, AccessTokenRepositoryInterface $accessTokenRepository, ScopeRepositoryInterface $scopeRepository, - $privateKeyPath, - $publicKeyPath, + $privateKey, + $publicKey, ResponseTypeInterface $responseType = null, AuthorizationValidatorInterface $authorizationValidator = null ) { $this->clientRepository = $clientRepository; $this->accessTokenRepository = $accessTokenRepository; $this->scopeRepository = $scopeRepository; - $this->privateKeyPath = $privateKeyPath; - $this->publicKeyPath = $publicKeyPath; + + if (!$privateKey instanceof CryptKey) { + $privateKey = new CryptKey($privateKey); + } + $this->privateKey = $privateKey; + + if (!$publicKey instanceof CryptKey) { + $publicKey = new CryptKey($publicKey); + } + $this->publicKey = $publicKey; + $this->responseType = $responseType; $this->authorizationValidator = $authorizationValidator; } @@ -106,8 +115,8 @@ class Server implements EmitterAwareInterface $grantType->setAccessTokenRepository($this->accessTokenRepository); $grantType->setClientRepository($this->clientRepository); $grantType->setScopeRepository($this->scopeRepository); - $grantType->setPrivateKeyPath($this->privateKeyPath); - $grantType->setPublicKeyPath($this->publicKeyPath); + $grantType->setPrivateKey($this->privateKey); + $grantType->setPublicKey($this->publicKey); $grantType->setEmitter($this->getEmitter()); $this->enabledGrantTypes[$grantType->getIdentifier()] = $grantType; @@ -118,8 +127,8 @@ class Server implements EmitterAwareInterface /** * Return an access token response. * - * @param \Psr\Http\Message\ServerRequestInterface|null $request - * @param \Psr\Http\Message\ResponseInterface|null $response + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Psr\Http\Message\ResponseInterface $response * * @throws \League\OAuth2\Server\Exception\OAuthServerException * @@ -171,8 +180,7 @@ class Server implements EmitterAwareInterface $this->responseType = new BearerTokenResponse($this->accessTokenRepository); } - $this->responseType->setPublicKeyPath($this->publicKeyPath); - $this->responseType->setPrivateKeyPath($this->privateKeyPath); + $this->responseType->setPrivateKey($this->privateKey); return $this->responseType; } @@ -186,8 +194,7 @@ class Server implements EmitterAwareInterface $this->authorizationValidator = new BearerTokenValidator($this->accessTokenRepository); } - $this->authorizationValidator->setPublicKeyPath($this->publicKeyPath); - $this->authorizationValidator->setPrivateKeyPath($this->privateKeyPath); + $this->authorizationValidator->setPublicKey($this->publicKey); return $this->authorizationValidator; } diff --git a/tests/CryptTraitTest.php b/tests/CryptTraitTest.php index fad2fdcf..364d712f 100644 --- a/tests/CryptTraitTest.php +++ b/tests/CryptTraitTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Utils; +use League\OAuth2\Server\CryptKey; use LeagueTests\Stubs\CryptTraitStub; class CryptTraitTest extends \PHPUnit_Framework_TestCase @@ -31,7 +32,7 @@ class CryptTraitTest extends \PHPUnit_Framework_TestCase */ public function testBadPrivateKey() { - $this->cryptStub->setPrivateKeyPath(__DIR__ . '/Stubs/public.key'); + $this->cryptStub->setPrivateKey(new CryptKey(__DIR__ . '/Stubs/public.key')); $this->cryptStub->doEncrypt(''); } @@ -40,7 +41,7 @@ class CryptTraitTest extends \PHPUnit_Framework_TestCase */ public function testBadPublicKey() { - $this->cryptStub->setPublicKeyPath(__DIR__ . '/Stubs/private.key'); + $this->cryptStub->setPublicKey(new CryptKey(__DIR__ . '/Stubs/private.key')); $this->cryptStub->doDecrypt(''); } } diff --git a/tests/Grant/AbstractGrantTest.php b/tests/Grant/AbstractGrantTest.php index cdde8764..db281430 100644 --- a/tests/Grant/AbstractGrantTest.php +++ b/tests/Grant/AbstractGrantTest.php @@ -3,6 +3,7 @@ namespace LeagueTests\Grant; use League\Event\Emitter; +use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntity; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface; @@ -23,8 +24,8 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase { /** @var AbstractGrant $grantMock */ $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); - $grantMock->setPrivateKeyPath('./private.key'); - $grantMock->setPublicKeyPath('./public.key'); + $grantMock->setPrivateKey(new CryptKey(__DIR__ . '/../Stubs/private.key')); + $grantMock->setPublicKey(new CryptKey(__DIR__ . '/../Stubs/public.key')); $grantMock->setEmitter(new Emitter()); } diff --git a/tests/Grant/AuthCodeGrantTest.php b/tests/Grant/AuthCodeGrantTest.php index 1dfb6974..6fe74782 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; @@ -99,8 +100,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -161,8 +162,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase ); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -214,8 +215,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase new \DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -260,8 +261,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase new \DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -312,8 +313,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase new \DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -370,8 +371,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase new \DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -426,8 +427,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -483,8 +484,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase ); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -542,8 +543,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase ); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -607,8 +608,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $grant->setScopeRepository($scopeRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [], @@ -665,8 +666,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [], @@ -711,8 +712,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [], @@ -762,8 +763,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [], @@ -831,8 +832,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [], @@ -897,8 +898,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [], @@ -963,8 +964,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [], diff --git a/tests/Grant/ImplicitGrantTest.php b/tests/Grant/ImplicitGrantTest.php index 06525b9c..100b97aa 100644 --- a/tests/Grant/ImplicitGrantTest.php +++ b/tests/Grant/ImplicitGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\ImplicitGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -77,8 +78,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -115,8 +116,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase public function testRespondToAuthorizationRequestMissingClientId() { $grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class)); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -152,8 +153,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase $grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class)); $grant->setClientRepository($clientRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -199,8 +200,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase $grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class)); $grant->setClientRepository($clientRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -252,8 +253,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase $grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class)); $grant->setClientRepository($clientRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -299,8 +300,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase $grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class)); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -350,8 +351,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase $grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class)); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ @@ -401,8 +402,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase $grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class)); $grant->setClientRepository($clientRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest( [ diff --git a/tests/Grant/RefreshTokenGrantTest.php b/tests/Grant/RefreshTokenGrantTest.php index 719b28c3..d48a5af2 100644 --- a/tests/Grant/RefreshTokenGrantTest.php +++ b/tests/Grant/RefreshTokenGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; use League\OAuth2\Server\Grant\RefreshTokenGrant; @@ -61,8 +62,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $oldRefreshToken = $this->cryptStub->doEncrypt( json_encode( @@ -116,8 +117,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $oldRefreshToken = $this->cryptStub->doEncrypt( json_encode( @@ -176,8 +177,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $oldRefreshToken = $this->cryptStub->doEncrypt( json_encode( @@ -224,8 +225,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $grant = new RefreshTokenGrant($refreshTokenRepositoryMock); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $serverRequest = new ServerRequest(); $serverRequest = $serverRequest->withParsedBody( @@ -257,8 +258,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $grant = new RefreshTokenGrant($refreshTokenRepositoryMock); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $oldRefreshToken = 'foobar'; @@ -297,8 +298,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $grant = new RefreshTokenGrant($refreshTokenRepositoryMock); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $oldRefreshToken = $this->cryptStub->doEncrypt( json_encode( @@ -344,8 +345,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $grant = new RefreshTokenGrant($refreshTokenRepositoryMock); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $oldRefreshToken = $this->cryptStub->doEncrypt( json_encode( @@ -392,8 +393,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase $grant = new RefreshTokenGrant($refreshTokenRepositoryMock); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); - $grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); + $grant->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); + $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $oldRefreshToken = $this->cryptStub->doEncrypt( json_encode( diff --git a/tests/Middleware/AuthenticationServerMiddlewareTest.php b/tests/Middleware/AuthenticationServerMiddlewareTest.php index 4acd5c89..bfed2651 100644 --- a/tests/Middleware/AuthenticationServerMiddlewareTest.php +++ b/tests/Middleware/AuthenticationServerMiddlewareTest.php @@ -27,8 +27,8 @@ class AuthenticationServerMiddlewareTest extends \PHPUnit_Framework_TestCase $clientRepository, $this->getMock(AccessTokenRepositoryInterface::class), $scopeRepositoryMock, - '', - '', + 'file://' . __DIR__ . '/../Stubs/private.key', + 'file://' . __DIR__ . '/../Stubs/public.key', new StubResponseType() ); @@ -60,8 +60,8 @@ class AuthenticationServerMiddlewareTest extends \PHPUnit_Framework_TestCase $clientRepository, $this->getMock(AccessTokenRepositoryInterface::class), $this->getMock(ScopeRepositoryInterface::class), - '', - '', + 'file://' . __DIR__ . '/../Stubs/private.key', + 'file://' . __DIR__ . '/../Stubs/public.key', new StubResponseType() ); diff --git a/tests/Middleware/ResourceServerMiddlewareTest.php b/tests/Middleware/ResourceServerMiddlewareTest.php index 960113db..bb3f7ab7 100644 --- a/tests/Middleware/ResourceServerMiddlewareTest.php +++ b/tests/Middleware/ResourceServerMiddlewareTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Middleware; +use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntity; use League\OAuth2\Server\Middleware\ResourceServerMiddleware; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -37,7 +38,7 @@ class ResourceServerMiddlewareTest extends \PHPUnit_Framework_TestCase $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); $accessToken->setClient($client); - $token = $accessToken->convertToJWT('file://' . __DIR__ . '/../Stubs/private.key'); + $token = $accessToken->convertToJWT(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $request = new ServerRequest(); $request = $request->withHeader('authorization', sprintf('Bearer %s', $token)); @@ -64,8 +65,8 @@ class ResourceServerMiddlewareTest extends \PHPUnit_Framework_TestCase $clientRepository, $this->getMock(AccessTokenRepositoryInterface::class), $this->getMock(ScopeRepositoryInterface::class), - '', - '', + 'file://' . __DIR__ . '/../Stubs/private.key', + 'file://' . __DIR__ . '/../Stubs/public.key', new StubResponseType() ); diff --git a/tests/ResponseTypes/BearerResponseTypeTest.php b/tests/ResponseTypes/BearerResponseTypeTest.php index a8b62f0e..3fb11168 100644 --- a/tests/ResponseTypes/BearerResponseTypeTest.php +++ b/tests/ResponseTypes/BearerResponseTypeTest.php @@ -3,6 +3,7 @@ namespace LeagueTests\ResponseTypes; use League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator; +use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntity; use League\OAuth2\Server\Entities\RefreshTokenEntity; use League\OAuth2\Server\Exception\OAuthServerException; @@ -21,8 +22,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); $responseType = new BearerTokenResponse($accessTokenRepositoryMock); - $responseType->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); - $responseType->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); + $responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); + $responseType->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); $client = new ClientEntity(); $client->setIdentifier('clientName'); @@ -66,8 +67,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase $accessTokenRepositoryMock->method('isAccessTokenRevoked')->willReturn(false); $responseType = new BearerTokenResponse($accessTokenRepositoryMock); - $responseType->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); - $responseType->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); + $responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); + $responseType->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); $client = new ClientEntity(); $client->setIdentifier('clientName'); @@ -90,8 +91,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase $json = json_decode((string) $response->getBody()); $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); - $authorizationValidator->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); - $authorizationValidator->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); + $authorizationValidator->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); + $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); $request = new ServerRequest(); $request = $request->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); @@ -110,8 +111,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase $accessTokenRepositoryMock->method('isAccessTokenRevoked')->willReturn(false); $responseType = new BearerTokenResponse($accessTokenRepositoryMock); - $responseType->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); - $responseType->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); + $responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); + $responseType->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); $client = new ClientEntity(); $client->setIdentifier('clientName'); @@ -134,8 +135,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase $json = json_decode((string) $response->getBody()); $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); - $authorizationValidator->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); - $authorizationValidator->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); + $authorizationValidator->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); + $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); $request = new ServerRequest(); $request = $request->withHeader('authorization', sprintf('Bearer %s', $json->access_token . 'foo')); @@ -156,8 +157,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase $accessTokenRepositoryMock->method('isAccessTokenRevoked')->willReturn(true); $responseType = new BearerTokenResponse($accessTokenRepositoryMock); - $responseType->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); - $responseType->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); + $responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); + $responseType->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); $client = new ClientEntity(); $client->setIdentifier('clientName'); @@ -180,8 +181,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase $json = json_decode((string) $response->getBody()); $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); - $authorizationValidator->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); - $authorizationValidator->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); + $authorizationValidator->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); + $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); $request = new ServerRequest(); $request = $request->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); @@ -201,12 +202,12 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); $responseType = new BearerTokenResponse($accessTokenRepositoryMock); - $responseType->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); - $responseType->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); + $responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); + $responseType->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); - $authorizationValidator->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); - $authorizationValidator->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); + $authorizationValidator->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); + $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); $request = new ServerRequest(); $request = $request->withHeader('authorization', 'Bearer blah'); diff --git a/tests/ServerTest.php b/tests/ServerTest.php index f61818cf..d3c693d6 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -28,8 +28,8 @@ class ServerTest extends \PHPUnit_Framework_TestCase $this->getMock(ClientRepositoryInterface::class), $this->getMock(AccessTokenRepositoryInterface::class), $this->getMock(ScopeRepositoryInterface::class), - '', - '', + 'file://' . __DIR__ . '/Stubs/private.key', + 'file://' . __DIR__ . '/Stubs/public.key', new StubResponseType() ); @@ -55,8 +55,8 @@ class ServerTest extends \PHPUnit_Framework_TestCase $clientRepository, $this->getMock(AccessTokenRepositoryInterface::class), $scopeRepositoryMock, - '', - '', + 'file://' . __DIR__ . '/Stubs/private.key', + 'file://' . __DIR__ . '/Stubs/public.key', new StubResponseType() ); @@ -125,8 +125,8 @@ class ServerTest extends \PHPUnit_Framework_TestCase $clientRepository, $this->getMock(AccessTokenRepositoryInterface::class), $this->getMock(ScopeRepositoryInterface::class), - '', - '' + 'file://' . __DIR__ . '/Stubs/private.key', + 'file://' . __DIR__ . '/Stubs/public.key' ); $abstractGrantReflection = new \ReflectionClass($server); @@ -144,8 +144,8 @@ class ServerTest extends \PHPUnit_Framework_TestCase $clientRepository, $this->getMock(AccessTokenRepositoryInterface::class), $this->getMock(ScopeRepositoryInterface::class), - '', - '' + 'file://' . __DIR__ . '/Stubs/private.key', + 'file://' . __DIR__ . '/Stubs/public.key' ); try { diff --git a/tests/Stubs/CryptTraitStub.php b/tests/Stubs/CryptTraitStub.php index 583a851c..2414c199 100644 --- a/tests/Stubs/CryptTraitStub.php +++ b/tests/Stubs/CryptTraitStub.php @@ -2,6 +2,7 @@ namespace LeagueTests\Stubs; +use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\CryptTrait; class CryptTraitStub @@ -10,8 +11,8 @@ class CryptTraitStub public function __construct() { - $this->setPrivateKeyPath('file://' . __DIR__ . '/private.key'); - $this->setPublicKeyPath('file://' . __DIR__ . '/public.key'); + $this->setPrivateKey(new CryptKey('file://' . __DIR__ . '/private.key')); + $this->setPublicKey(new CryptKey('file://' . __DIR__ . '/public.key')); } public function doEncrypt($unencryptedData)