diff --git a/composer.json b/composer.json index 063ef0cc4..509f5ebfb 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require-dev": { "phpunit/phpunit": "^9.6.15", - "laminas/laminas-diactoros": "^3.3.0", + "nyholm/psr7": "^1.8", "phpstan/phpstan": "^1.10.55", "phpstan/phpstan-phpunit": "^1.3.15", "roave/security-advisories": "dev-master", diff --git a/examples/composer.json b/examples/composer.json index 7d2000be5..8776a9551 100644 --- a/examples/composer.json +++ b/examples/composer.json @@ -4,10 +4,10 @@ }, "require-dev": { "league/event": "^3.0", - "lcobucci/jwt": "^3.4.6 || ^4.0.4", - "psr/http-message": "^1.0.1", - "defuse/php-encryption": "^2.2.1", - "laminas/laminas-diactoros": "^2.5.0" + "lcobucci/jwt": "^3.4.6 || ^4.0.4 || ^5.0", + "psr/http-message": "^1.1 || ^2.0", + "defuse/php-encryption": "^2.4", + "nyholm/psr7": "^1.8" }, "autoload": { "psr-4": { diff --git a/examples/composer.lock b/examples/composer.lock index 58f1c60cb..ae308fed1 100644 --- a/examples/composer.lock +++ b/examples/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ac8c2c0c3717f72036b55ab34445a89d", + "content-hash": "b2041830e6c4a6fadd7f9c9a57c86591", "packages": [ { "name": "nikic/fast-route", @@ -366,202 +366,40 @@ }, "time": "2023-06-19T06:10:36+00:00" }, - { - "name": "laminas/laminas-diactoros", - "version": "2.26.0", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-diactoros.git", - "reference": "6584d44eb8e477e89d453313b858daac6183cddc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-diactoros/zipball/6584d44eb8e477e89d453313b858daac6183cddc", - "reference": "6584d44eb8e477e89d453313b858daac6183cddc", - "shasum": "" - }, - "require": { - "php": "~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0", - "psr/http-factory": "^1.0", - "psr/http-message": "^1.1" - }, - "conflict": { - "zendframework/zend-diactoros": "*" - }, - "provide": { - "psr/http-factory-implementation": "1.0", - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "ext-curl": "*", - "ext-dom": "*", - "ext-gd": "*", - "ext-libxml": "*", - "http-interop/http-factory-tests": "^0.9.0", - "laminas/laminas-coding-standard": "^2.5", - "php-http/psr7-integration-tests": "^1.2", - "phpunit/phpunit": "^9.5.28", - "psalm/plugin-phpunit": "^0.18.4", - "vimeo/psalm": "^5.6" - }, - "type": "library", - "extra": { - "laminas": { - "config-provider": "Laminas\\Diactoros\\ConfigProvider", - "module": "Laminas\\Diactoros" - } - }, - "autoload": { - "files": [ - "src/functions/create_uploaded_file.php", - "src/functions/marshal_headers_from_sapi.php", - "src/functions/marshal_method_from_sapi.php", - "src/functions/marshal_protocol_version_from_sapi.php", - "src/functions/marshal_uri_from_sapi.php", - "src/functions/normalize_server.php", - "src/functions/normalize_uploaded_files.php", - "src/functions/parse_cookie_header.php", - "src/functions/create_uploaded_file.legacy.php", - "src/functions/marshal_headers_from_sapi.legacy.php", - "src/functions/marshal_method_from_sapi.legacy.php", - "src/functions/marshal_protocol_version_from_sapi.legacy.php", - "src/functions/marshal_uri_from_sapi.legacy.php", - "src/functions/normalize_server.legacy.php", - "src/functions/normalize_uploaded_files.legacy.php", - "src/functions/parse_cookie_header.legacy.php" - ], - "psr-4": { - "Laminas\\Diactoros\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "PSR HTTP Message implementations", - "homepage": "https://laminas.dev", - "keywords": [ - "http", - "laminas", - "psr", - "psr-17", - "psr-7" - ], - "support": { - "chat": "https://laminas.dev/chat", - "docs": "https://docs.laminas.dev/laminas-diactoros/", - "forum": "https://discourse.laminas.dev", - "issues": "https://github.com/laminas/laminas-diactoros/issues", - "rss": "https://github.com/laminas/laminas-diactoros/releases.atom", - "source": "https://github.com/laminas/laminas-diactoros" - }, - "funding": [ - { - "url": "https://funding.communitybridge.org/projects/laminas-project", - "type": "community_bridge" - } - ], - "time": "2023-10-29T16:17:44+00:00" - }, - { - "name": "lcobucci/clock", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/lcobucci/clock.git", - "reference": "039ef98c6b57b101d10bd11d8fdfda12cbd996dc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/lcobucci/clock/zipball/039ef98c6b57b101d10bd11d8fdfda12cbd996dc", - "reference": "039ef98c6b57b101d10bd11d8fdfda12cbd996dc", - "shasum": "" - }, - "require": { - "php": "~8.1.0 || ~8.2.0", - "psr/clock": "^1.0" - }, - "provide": { - "psr/clock-implementation": "1.0" - }, - "require-dev": { - "infection/infection": "^0.26", - "lcobucci/coding-standard": "^9.0", - "phpstan/extension-installer": "^1.2", - "phpstan/phpstan": "^1.9.4", - "phpstan/phpstan-deprecation-rules": "^1.1.1", - "phpstan/phpstan-phpunit": "^1.3.2", - "phpstan/phpstan-strict-rules": "^1.4.4", - "phpunit/phpunit": "^9.5.27" - }, - "type": "library", - "autoload": { - "psr-4": { - "Lcobucci\\Clock\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Luís Cobucci", - "email": "lcobucci@gmail.com" - } - ], - "description": "Yet another clock abstraction", - "support": { - "issues": "https://github.com/lcobucci/clock/issues", - "source": "https://github.com/lcobucci/clock/tree/3.0.0" - }, - "funding": [ - { - "url": "https://github.com/lcobucci", - "type": "github" - }, - { - "url": "https://www.patreon.com/lcobucci", - "type": "patreon" - } - ], - "time": "2022-12-19T15:00:24+00:00" - }, { "name": "lcobucci/jwt", - "version": "4.3.0", + "version": "5.4.0", "source": { "type": "git", "url": "https://github.com/lcobucci/jwt.git", - "reference": "4d7de2fe0d51a96418c0d04004986e410e87f6b4" + "reference": "aac4fd512681fd5cb4b77d2105ab7ec700c72051" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/lcobucci/jwt/zipball/4d7de2fe0d51a96418c0d04004986e410e87f6b4", - "reference": "4d7de2fe0d51a96418c0d04004986e410e87f6b4", + "url": "https://api.github.com/repos/lcobucci/jwt/zipball/aac4fd512681fd5cb4b77d2105ab7ec700c72051", + "reference": "aac4fd512681fd5cb4b77d2105ab7ec700c72051", "shasum": "" }, "require": { - "ext-hash": "*", - "ext-json": "*", - "ext-mbstring": "*", "ext-openssl": "*", "ext-sodium": "*", - "lcobucci/clock": "^2.0 || ^3.0", - "php": "^7.4 || ^8.0" + "php": "~8.2.0 || ~8.3.0 || ~8.4.0", + "psr/clock": "^1.0" }, "require-dev": { - "infection/infection": "^0.21", - "lcobucci/coding-standard": "^6.0", - "mikey179/vfsstream": "^1.6.7", + "infection/infection": "^0.29", + "lcobucci/clock": "^3.2", + "lcobucci/coding-standard": "^11.0", "phpbench/phpbench": "^1.2", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/php-invoker": "^3.1", - "phpunit/phpunit": "^9.5" + "phpstan/extension-installer": "^1.2", + "phpstan/phpstan": "^1.10.7", + "phpstan/phpstan-deprecation-rules": "^1.1.3", + "phpstan/phpstan-phpunit": "^1.3.10", + "phpstan/phpstan-strict-rules": "^1.5.0", + "phpunit/phpunit": "^11.1" + }, + "suggest": { + "lcobucci/clock": ">= 3.2" }, "type": "library", "autoload": { @@ -587,7 +425,7 @@ ], "support": { "issues": "https://github.com/lcobucci/jwt/issues", - "source": "https://github.com/lcobucci/jwt/tree/4.3.0" + "source": "https://github.com/lcobucci/jwt/tree/5.4.0" }, "funding": [ { @@ -599,20 +437,20 @@ "type": "patreon" } ], - "time": "2023-01-02T13:28:00+00:00" + "time": "2024-10-08T22:06:45+00:00" }, { "name": "league/event", - "version": "3.0.2", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/thephpleague/event.git", - "reference": "221867a61087ee265ca07bd39aa757879afca820" + "reference": "ec38ff7ea10cad7d99a79ac937fbcffb9334c210" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/event/zipball/221867a61087ee265ca07bd39aa757879afca820", - "reference": "221867a61087ee265ca07bd39aa757879afca820", + "url": "https://api.github.com/repos/thephpleague/event/zipball/ec38ff7ea10cad7d99a79ac937fbcffb9334c210", + "reference": "ec38ff7ea10cad7d99a79ac937fbcffb9334c210", "shasum": "" }, "require": { @@ -656,9 +494,87 @@ ], "support": { "issues": "https://github.com/thephpleague/event/issues", - "source": "https://github.com/thephpleague/event/tree/3.0.2" + "source": "https://github.com/thephpleague/event/tree/3.0.3" + }, + "time": "2024-09-04T16:06:53+00:00" + }, + { + "name": "nyholm/psr7", + "version": "1.8.2", + "source": { + "type": "git", + "url": "https://github.com/Nyholm/psr7.git", + "reference": "a71f2b11690f4b24d099d6b16690a90ae14fc6f3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Nyholm/psr7/zipball/a71f2b11690f4b24d099d6b16690a90ae14fc6f3", + "reference": "a71f2b11690f4b24d099d6b16690a90ae14fc6f3", + "shasum": "" + }, + "require": { + "php": ">=7.2", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0" + }, + "provide": { + "php-http/message-factory-implementation": "1.0", + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "http-interop/http-factory-tests": "^0.9", + "php-http/message-factory": "^1.0", + "php-http/psr7-integration-tests": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.4", + "symfony/error-handler": "^4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8-dev" + } + }, + "autoload": { + "psr-4": { + "Nyholm\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com" + }, + { + "name": "Martijn van der Ven", + "email": "martijn@vanderven.se" + } + ], + "description": "A fast PHP7 implementation of PSR-7", + "homepage": "https://tnyholm.se", + "keywords": [ + "psr-17", + "psr-7" + ], + "support": { + "issues": "https://github.com/Nyholm/psr7/issues", + "source": "https://github.com/Nyholm/psr7/tree/1.8.2" }, - "time": "2022-10-29T09:31:25+00:00" + "funding": [ + { + "url": "https://github.com/Zegnat", + "type": "github" + }, + { + "url": "https://github.com/nyholm", + "type": "github" + } + ], + "time": "2024-09-09T07:06:30+00:00" }, { "name": "paragonie/random_compat", @@ -810,20 +726,20 @@ }, { "name": "psr/http-factory", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/php-fig/http-factory.git", - "reference": "e616d01114759c4c489f93b099585439f795fe35" + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", - "reference": "e616d01114759c4c489f93b099585439f795fe35", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", "shasum": "" }, "require": { - "php": ">=7.0.0", + "php": ">=7.1", "psr/http-message": "^1.0 || ^2.0" }, "type": "library", @@ -847,7 +763,7 @@ "homepage": "https://www.php-fig.org/" } ], - "description": "Common interfaces for PSR-7 HTTP message factories", + "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", "keywords": [ "factory", "http", @@ -859,9 +775,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-factory/tree/1.0.2" + "source": "https://github.com/php-fig/http-factory" }, - "time": "2023-04-10T20:10:41+00:00" + "time": "2024-04-15T12:06:14+00:00" } ], "aliases": [], diff --git a/examples/public/auth_code.php b/examples/public/auth_code.php index 815d86dee..1a2fa118d 100644 --- a/examples/public/auth_code.php +++ b/examples/public/auth_code.php @@ -10,10 +10,10 @@ declare(strict_types=1); -use Laminas\Diactoros\Stream; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\AuthCodeGrant; +use Nyholm\Psr7\Stream; use OAuth2ServerExamples\Entities\UserEntity; use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\AuthCodeRepository; @@ -84,8 +84,7 @@ } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); } catch (Exception $exception) { - $body = new Stream('php://temp', 'r+'); - $body->write($exception->getMessage()); + $body = Stream::create($exception->getMessage()); return $response->withStatus(500)->withBody($body); } @@ -100,8 +99,7 @@ } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); } catch (Exception $exception) { - $body = new Stream('php://temp', 'r+'); - $body->write($exception->getMessage()); + $body = Stream::create($exception->getMessage()); return $response->withStatus(500)->withBody($body); } diff --git a/examples/public/client_credentials.php b/examples/public/client_credentials.php index 080b06e07..113ebcbc2 100644 --- a/examples/public/client_credentials.php +++ b/examples/public/client_credentials.php @@ -12,10 +12,10 @@ include __DIR__ . '/../vendor/autoload.php'; -use Laminas\Diactoros\Stream; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\ClientCredentialsGrant; +use Nyholm\Psr7\Stream; use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ScopeRepository; @@ -68,8 +68,7 @@ return $exception->generateHttpResponse($response); } catch (Exception $exception) { // Unknown exception - $body = new Stream('php://temp', 'r+'); - $body->write($exception->getMessage()); + $body = Stream::create($exception->getMessage()); return $response->withStatus(500)->withBody($body); } diff --git a/examples/public/implicit.php b/examples/public/implicit.php index 6c54b8f2c..f12f80f69 100644 --- a/examples/public/implicit.php +++ b/examples/public/implicit.php @@ -10,7 +10,6 @@ declare(strict_types=1); -use Laminas\Diactoros\Stream; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\ImplicitGrant; @@ -73,8 +72,7 @@ } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); } catch (Exception $exception) { - $body = new Stream('php://temp', 'r+'); - $body->write($exception->getMessage()); + $body = Stream::create($exception->getMessage()); return $response->withStatus(500)->withBody($body); } diff --git a/examples/public/middleware_use.php b/examples/public/middleware_use.php index 49bb5b5bb..688e2fa21 100644 --- a/examples/public/middleware_use.php +++ b/examples/public/middleware_use.php @@ -12,7 +12,6 @@ include __DIR__ . '/../vendor/autoload.php'; -use Laminas\Diactoros\Stream; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Grant\AuthCodeGrant; use League\OAuth2\Server\Grant\RefreshTokenGrant; @@ -102,8 +101,7 @@ $params['email'] = 'alex@example.com'; } - $body = new Stream('php://temp', 'r+'); - $body->write(json_encode($params)); + $body = Stream::create(json_encode($params)); return $response->withBody($body); }); diff --git a/tests/AuthorizationServerTest.php b/tests/AuthorizationServerTest.php index 6e41a17f3..42d0b3d05 100644 --- a/tests/AuthorizationServerTest.php +++ b/tests/AuthorizationServerTest.php @@ -6,9 +6,6 @@ use DateInterval; use Defuse\Crypto\Key; -use Laminas\Diactoros\Response; -use Laminas\Diactoros\ServerRequest; -use Laminas\Diactoros\ServerRequestFactory; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\CryptKeyInterface; use League\OAuth2\Server\Exception\OAuthServerException; @@ -28,6 +25,8 @@ use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\UserEntity; +use Nyholm\Psr7\Response; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; use ReflectionClass; @@ -81,7 +80,7 @@ public function testRespondToRequestInvalidGrantType(): void $server->enableGrantType(new ClientCredentialsGrant(), new DateInterval('PT1M')); try { - $server->respondToAccessTokenRequest(ServerRequestFactory::fromGlobals(), new Response()); + $server->respondToAccessTokenRequest(new ServerRequest('', ''), new Response()); } catch (OAuthServerException $e) { self::assertEquals('unsupported_grant_type', $e->getErrorType()); self::assertEquals(400, $e->getHttpStatusCode()); @@ -119,10 +118,13 @@ public function testRespondToRequest(): void $server->setDefaultScope(self::DEFAULT_SCOPE); $server->enableGrantType(new ClientCredentialsGrant(), new DateInterval('PT1M')); - $_POST['grant_type'] = 'client_credentials'; - $_POST['client_id'] = 'foo'; - $_POST['client_secret'] = 'bar'; - $response = $server->respondToAccessTokenRequest(ServerRequestFactory::fromGlobals(), new Response()); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'client_credentials', + 'client_id' => 'foo', + 'client_secret' => 'bar', + ]); + + $response = $server->respondToAccessTokenRequest($request, new Response()); self::assertEquals(200, $response->getStatusCode()); } @@ -300,19 +302,10 @@ public function testValidateAuthorizationRequest(): void $server->setDefaultScope(self::DEFAULT_SCOPE); $server->enableGrantType($grant); - $request = new ServerRequest( - [], - [], - null, - null, - 'php://input', - $headers = [], - $cookies = [], - $queryParams = [ - 'response_type' => 'code', - 'client_id' => 'foo', - ] - ); + $request = (new ServerRequest('', ''))->withQueryParams([ + 'response_type' => 'code', + 'client_id' => 'foo', + ]); self::assertInstanceOf(AuthorizationRequest::class, $server->validateAuthorizationRequest($request)); } @@ -327,7 +320,7 @@ public function testValidateAuthorizationRequestUnregistered(): void 'file://' . __DIR__ . '/Stubs/public.key' ); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', ]); diff --git a/tests/AuthorizationValidators/BearerTokenValidatorTest.php b/tests/AuthorizationValidators/BearerTokenValidatorTest.php index 148473eea..d041cf5cd 100644 --- a/tests/AuthorizationValidators/BearerTokenValidatorTest.php +++ b/tests/AuthorizationValidators/BearerTokenValidatorTest.php @@ -6,13 +6,13 @@ use DateInterval; use DateTimeImmutable; -use Laminas\Diactoros\ServerRequest; use Lcobucci\JWT\Signer\Key\InMemory; use Lcobucci\JWT\Signer\Rsa\Sha256; use League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; use ReflectionClass; @@ -41,7 +41,7 @@ public function testBearerTokenValidatorAcceptsValidToken(): void ->withClaim('scopes', 'scope1 scope2 scope3 scope4') ->getToken(new Sha256(), InMemory::file(__DIR__ . '/../Stubs/private.key')); - $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $validJwt->toString())); + $request = (new ServerRequest('', ''))->withHeader('authorization', sprintf('Bearer %s', $validJwt->toString())); $validRequest = $bearerTokenValidator->validateAuthorization($request); @@ -69,7 +69,7 @@ public function testBearerTokenValidatorRejectsExpiredToken(): void ->withClaim('scopes', 'scope1 scope2 scope3 scope4') ->getToken(new Sha256(), InMemory::file(__DIR__ . '/../Stubs/private.key')); - $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $expiredJwt->toString())); + $request = (new ServerRequest('', ''))->withHeader('authorization', sprintf('Bearer %s', $expiredJwt->toString())); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(9); @@ -89,7 +89,6 @@ public function testBearerTokenValidatorAcceptsExpiredTokenWithinLeeway(): void $bearerTokenValidatorReflection = new ReflectionClass(BearerTokenValidator::class); $jwtConfiguration = $bearerTokenValidatorReflection->getProperty('jwtConfiguration'); - $jwtConfiguration->setAccessible(true); $jwtTokenFromFutureWithinLeeway = $jwtConfiguration->getValue($bearerTokenValidator)->builder() ->permittedFor('client-id') @@ -101,7 +100,7 @@ public function testBearerTokenValidatorAcceptsExpiredTokenWithinLeeway(): void ->withClaim('scopes', 'scope1 scope2 scope3 scope4') ->getToken(new Sha256(), InMemory::file(__DIR__ . '/../Stubs/private.key')); - $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $jwtTokenFromFutureWithinLeeway->toString())); + $request = (new ServerRequest('', ''))->withHeader('authorization', sprintf('Bearer %s', $jwtTokenFromFutureWithinLeeway->toString())); $validRequest = $bearerTokenValidator->validateAuthorization($request); @@ -132,7 +131,7 @@ public function testBearerTokenValidatorRejectsExpiredTokenBeyondLeeway(): void ->withClaim('scopes', 'scope1 scope2 scope3 scope4') ->getToken(new Sha256(), InMemory::file(__DIR__ . '/../Stubs/private.key')); - $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $jwtTokenFromFutureBeyondLeeway->toString())); + $request = (new ServerRequest('', ''))->withHeader('authorization', sprintf('Bearer %s', $jwtTokenFromFutureBeyondLeeway->toString())); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(9); diff --git a/tests/Exception/OAuthServerExceptionTest.php b/tests/Exception/OAuthServerExceptionTest.php index 93db59f2a..51c7d227d 100644 --- a/tests/Exception/OAuthServerExceptionTest.php +++ b/tests/Exception/OAuthServerExceptionTest.php @@ -5,11 +5,11 @@ namespace LeagueTests\Exception; use Exception; -use Laminas\Diactoros\Response; -use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\AbstractGrant; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; +use Nyholm\Psr7\Response; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; use ReflectionClass; @@ -18,7 +18,7 @@ class OAuthServerExceptionTest extends TestCase { public function testInvalidClientExceptionSetsAuthenticateHeader(): void { - $serverRequest = (new ServerRequest()) + $serverRequest = (new ServerRequest('', '')) ->withParsedBody([ 'client_id' => 'foo', ]) @@ -35,7 +35,7 @@ public function testInvalidClientExceptionSetsAuthenticateHeader(): void public function testInvalidClientExceptionSetsBearerAuthenticateHeader(): void { - $serverRequest = (new ServerRequest()) + $serverRequest = (new ServerRequest('', '')) ->withParsedBody([ 'client_id' => 'foo', ]) @@ -52,7 +52,7 @@ public function testInvalidClientExceptionSetsBearerAuthenticateHeader(): void public function testInvalidClientExceptionOmitsAuthenticateHeader(): void { - $serverRequest = (new ServerRequest()) + $serverRequest = (new ServerRequest('', '')) ->withParsedBody([ 'client_id' => 'foo', ]); @@ -68,7 +68,7 @@ public function testInvalidClientExceptionOmitsAuthenticateHeader(): void public function testInvalidClientExceptionOmitsAuthenticateHeaderGivenEmptyAuthorizationHeader(): void { - $serverRequest = (new ServerRequest()) + $serverRequest = (new ServerRequest('', '')) ->withParsedBody([ 'client_id' => 'foo', ]) diff --git a/tests/Grant/AbstractGrantTest.php b/tests/Grant/AbstractGrantTest.php index adfb880be..9f1ddc407 100644 --- a/tests/Grant/AbstractGrantTest.php +++ b/tests/Grant/AbstractGrantTest.php @@ -5,7 +5,6 @@ namespace LeagueTests\Grant; use DateInterval; -use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\AuthCodeEntityInterface; @@ -24,6 +23,7 @@ use LeagueTests\Stubs\RefreshTokenEntity; use LeagueTests\Stubs\ScopeEntity; use LogicException; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; use ReflectionClass; @@ -37,7 +37,7 @@ public function testHttpBasicWithPassword(): void $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withHeader('Authorization', 'Basic ' . base64_encode('Open:Sesame')); + $serverRequest = (new ServerRequest('', ''))->withHeader('Authorization', 'Basic ' . base64_encode('Open:Sesame')); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -50,7 +50,7 @@ public function testHttpBasicNoPassword(): void $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withHeader('Authorization', 'Basic ' . base64_encode('Open:')); + $serverRequest = (new ServerRequest('', ''))->withHeader('Authorization', 'Basic ' . base64_encode('Open:')); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -63,7 +63,7 @@ public function testHttpBasicNotBasic(): void $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withHeader('Authorization', 'Foo ' . base64_encode('Open:Sesame')); + $serverRequest = (new ServerRequest('', ''))->withHeader('Authorization', 'Foo ' . base64_encode('Open:Sesame')); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -76,7 +76,7 @@ public function testHttpBasicCaseInsensitive(): void $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withHeader('Authorization', 'bAsIc ' . base64_encode('Open:Sesame')); + $serverRequest = (new ServerRequest('', ''))->withHeader('Authorization', 'bAsIc ' . base64_encode('Open:Sesame')); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -89,7 +89,7 @@ public function testHttpBasicNotBase64(): void $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withHeader('Authorization', 'Basic ||'); + $serverRequest = (new ServerRequest('', ''))->withHeader('Authorization', 'Basic ||'); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -102,7 +102,7 @@ public function testHttpBasicNoColon(): void $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withHeader('Authorization', 'Basic ' . base64_encode('OpenSesame')); + $serverRequest = (new ServerRequest('', ''))->withHeader('Authorization', 'Basic ' . base64_encode('OpenSesame')); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -119,20 +119,10 @@ public function testGetClientCredentialsClientSecretNotAString(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'client_id' => 'client_id', - 'client_secret' => ['not', 'a', 'string'], - ] - ); + $serverRequest = (new ServerRequest('', ''))->withQueryParams([ + 'client_id' => 'client_id', + 'client_secret' => ['not', 'a', 'string'], + ]); $getClientCredentialsMethod = $abstractGrantReflection->getMethod('getClientCredentials'); $getClientCredentialsMethod->setAccessible(true); @@ -157,7 +147,7 @@ public function testValidateClientPublic(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', ]); @@ -184,7 +174,7 @@ public function testValidateClientConfidential(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'redirect_uri' => 'http://foo/bar', @@ -209,7 +199,7 @@ public function testValidateClientMissingClientId(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); + $serverRequest = new ServerRequest('', ''); $validateClientMethod = $abstractGrantReflection->getMethod('validateClient'); $validateClientMethod->setAccessible(true); @@ -229,7 +219,7 @@ public function testValidateClientMissingClientSecret(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', ]); @@ -252,7 +242,7 @@ public function testValidateClientInvalidClientSecret(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'foo', ]); @@ -278,7 +268,7 @@ public function testValidateClientInvalidRedirectUri(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'redirect_uri' => 'http://bar/foo', ]); @@ -304,7 +294,7 @@ public function testValidateClientInvalidRedirectUriArray(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'redirect_uri' => 'http://bar/foo', ]); @@ -330,7 +320,7 @@ public function testValidateClientMalformedRedirectUri(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'redirect_uri' => ['not', 'a', 'string'], ]); @@ -354,7 +344,7 @@ public function testValidateClientBadClient(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', ]); @@ -373,7 +363,7 @@ public function testCanRespondToRequest(): void $grantMock->method('getIdentifier')->willReturn('foobar'); $grantMock->setDefaultScope('defaultScope'); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'grant_type' => 'foobar', ]); @@ -490,7 +480,7 @@ public function testGetCookieParameter(): void $method = $abstractGrantReflection->getMethod('getCookieParameter'); $method->setAccessible(true); - $serverRequest = (new ServerRequest())->withCookieParams([ + $serverRequest = (new ServerRequest('', ''))->withCookieParams([ 'foo' => 'bar', ]); @@ -507,7 +497,7 @@ public function testGetQueryStringParameter(): void $method = $abstractGrantReflection->getMethod('getQueryStringParameter'); $method->setAccessible(true); - $serverRequest = (new ServerRequest())->withQueryParams([ + $serverRequest = (new ServerRequest('', ''))->withQueryParams([ 'foo' => 'bar', ]); @@ -556,7 +546,7 @@ public function testGenerateUniqueIdentifier(): void public function testCanRespondToAuthorizationRequest(): void { $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); - self::assertFalse($grantMock->canRespondToAuthorizationRequest(new ServerRequest())); + self::assertFalse($grantMock->canRespondToAuthorizationRequest(new ServerRequest('', ''))); } public function testValidateAuthorizationRequest(): void @@ -565,7 +555,7 @@ public function testValidateAuthorizationRequest(): void $this->expectException(LogicException::class); - $grantMock->validateAuthorizationRequest(new ServerRequest()); + $grantMock->validateAuthorizationRequest(new ServerRequest('', '')); } public function testCompleteAuthorizationRequest(): void diff --git a/tests/Grant/AuthCodeGrantTest.php b/tests/Grant/AuthCodeGrantTest.php index fc6ac07c3..c11060069 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -5,8 +5,6 @@ namespace LeagueTests\Grant; use DateInterval; -use Laminas\Diactoros\Response; -use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; @@ -28,6 +26,8 @@ use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\UserEntity; use LogicException; +use Nyholm\Psr7\Response; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; use function json_encode; @@ -70,19 +70,10 @@ public function testCanRespondToAuthorizationRequest(): void new DateInterval('PT10M') ); - $request = new ServerRequest( - [], - [], - null, - null, - 'php://input', - $headers = [], - $cookies = [], - $queryParams = [ - 'response_type' => 'code', - 'client_id' => 'foo', - ] - ); + $request = (new ServerRequest('', ''))->withQueryParams([ + 'response_type' => 'code', + 'client_id' => 'foo', + ]); self::assertTrue($grant->canRespondToAuthorizationRequest($request)); } @@ -109,20 +100,11 @@ public function testValidateAuthorizationRequest(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = new ServerRequest( - [], - [], - null, - null, - 'php://input', - [], - [], - [ - 'response_type' => 'code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - ] - ); + $request = (new ServerRequest('', ''))->withQueryParams([ + 'response_type' => 'code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + ]); self::assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request)); } @@ -148,20 +130,11 @@ public function testValidateAuthorizationRequestRedirectUriArray(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = new ServerRequest( - [], - [], - null, - null, - 'php://input', - [], - [], - [ - 'response_type' => 'code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - ] - ); + $request = (new ServerRequest('', ''))->withQueryParams([ + 'response_type' => 'code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + ]); self::assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request)); } @@ -188,19 +161,10 @@ public function testValidateAuthorizationRequestWithoutRedirectUri(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = new ServerRequest( - [], - [], - null, - null, - 'php://input', - [], - [], - [ - 'response_type' => 'code', - 'client_id' => 'foo', - ] - ); + $request = (new ServerRequest('', ''))->withQueryParams([ + 'response_type' => 'code', + 'client_id' => 'foo', + ]); $authorizationRequest = $grant->validateAuthorizationRequest($request); self::assertInstanceOf(AuthorizationRequest::class, $authorizationRequest); @@ -229,21 +193,12 @@ public function testValidateAuthorizationRequestCodeChallenge(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = new ServerRequest( - [], - [], - null, - null, - 'php://input', - [], - [], - [ - 'response_type' => 'code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code_challenge' => self::CODE_CHALLENGE, - ] - ); + $request = (new ServerRequest('', ''))->withQueryParams([ + 'response_type' => 'code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code_challenge' => self::CODE_CHALLENGE, + ]); self::assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request)); } @@ -266,7 +221,7 @@ public function testValidateAuthorizationRequestCodeChallengeInvalidLengthTooSho $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => self::REDIRECT_URI, @@ -296,7 +251,7 @@ public function testValidateAuthorizationRequestCodeChallengeInvalidLengthTooLon $grant->setDefaultScope(self::DEFAULT_SCOPE); $grant->setScopeRepository($scopeRepositoryMock); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => self::REDIRECT_URI, @@ -326,7 +281,7 @@ public function testValidateAuthorizationRequestCodeChallengeInvalidCharacters() $grant->setDefaultScope(self::DEFAULT_SCOPE); $grant->setScopeRepository($scopeRepositoryMock); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => self::REDIRECT_URI, @@ -349,7 +304,7 @@ public function testValidateAuthorizationRequestMissingClientId(): void ); $grant->setClientRepository($clientRepositoryMock); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', ]); @@ -371,7 +326,7 @@ public function testValidateAuthorizationRequestInvalidClientId(): void ); $grant->setClientRepository($clientRepositoryMock); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', ]); @@ -396,7 +351,7 @@ public function testValidateAuthorizationRequestBadRedirectUriString(): void ); $grant->setClientRepository($clientRepositoryMock); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => 'http://bar', @@ -422,7 +377,7 @@ public function testValidateAuthorizationRequestBadRedirectUriArray(): void ); $grant->setClientRepository($clientRepositoryMock); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => 'http://bar', @@ -455,7 +410,7 @@ public function testValidateAuthorizationRequestInvalidCodeChallengeMethod(): vo $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => self::REDIRECT_URI, @@ -584,31 +539,21 @@ public function testRespondToAccessTokenRequest(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + ], JSON_THROW_ON_ERROR) + ), + ]); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -654,30 +599,20 @@ public function testRespondToAccessTokenRequestWithDefaultRedirectUri(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => null, - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => null, + ], JSON_THROW_ON_ERROR) + ), + ]); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -715,18 +650,9 @@ public function testRespondToAccessTokenRequestUsingHttpBasicAuth(): void $authCodeGrant->setEncryptionKey($this->cryptStub->getKey()); $authCodeGrant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [ - 'Authorization' => 'Basic Zm9vOmJhcg==', - ], - [], - [], - [ + $request = (new ServerRequest('', '')) + ->withHeader('Authorization', 'Basic Zm9vOmJhcg==') + ->withParsedBody([ 'grant_type' => 'authorization_code', 'redirect_uri' => self::REDIRECT_URI, 'code' => $this->cryptStub->doEncrypt( @@ -739,8 +665,7 @@ public function testRespondToAccessTokenRequestUsingHttpBasicAuth(): void 'redirect_uri' => self::REDIRECT_URI, ], JSON_THROW_ON_ERROR) ), - ] - ); + ]); /** @var StubResponseType $response */ $response = $authCodeGrant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -781,31 +706,21 @@ public function testRespondToAccessTokenRequestForPublicClient(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + ], JSON_THROW_ON_ERROR) + ), + ]); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -846,31 +761,21 @@ public function testRespondToAccessTokenRequestNullRefreshToken(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + ], JSON_THROW_ON_ERROR) + ), + ]); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -917,34 +822,24 @@ public function testRespondToAccessTokenRequestCodeChallengePlain(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code_verifier' => self::CODE_VERIFIER, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - 'code_challenge' => self::CODE_VERIFIER, - 'code_challenge_method' => 'plain', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code_verifier' => self::CODE_VERIFIER, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + 'code_challenge' => self::CODE_VERIFIER, + 'code_challenge_method' => 'plain', + ], JSON_THROW_ON_ERROR) + ), + ]); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -991,34 +886,24 @@ public function testRespondToAccessTokenRequestCodeChallengeS256(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code_verifier' => self::CODE_VERIFIER, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - 'code_challenge' => self::CODE_CHALLENGE, - 'code_challenge_method' => 'S256', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code_verifier' => self::CODE_VERIFIER, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + 'code_challenge' => self::CODE_CHALLENGE, + 'code_challenge_method' => 'S256', + ], JSON_THROW_ON_ERROR) + ), + ]); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -1062,35 +947,25 @@ public function testPKCEDowngradeBlocked(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code_verifier' => self::CODE_VERIFIER, - 'code' => $this->cryptStub->doEncrypt( - json_encode( - [ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - ], - JSON_THROW_ON_ERROR - ) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code_verifier' => self::CODE_VERIFIER, + 'code' => $this->cryptStub->doEncrypt( + json_encode( + [ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + ], + JSON_THROW_ON_ERROR + ) + ), + ]); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -1120,28 +995,18 @@ public function testRespondToAccessTokenRequestMissingRedirectUri(): void $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'client_id' => 'foo', - 'grant_type' => 'authorization_code', - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'redirect_uri' => 'http://foo/bar', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'client_id' => 'foo', + 'grant_type' => 'authorization_code', + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'redirect_uri' => 'http://foo/bar', + ], JSON_THROW_ON_ERROR) + ), + ]); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -1170,29 +1035,19 @@ public function testRespondToAccessTokenRequestRedirectUriMismatch(): void $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'client_id' => 'foo', - 'grant_type' => 'authorization_code', - 'redirect_uri' => 'http://bar/foo', - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'redirect_uri' => 'http://foo/bar', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'client_id' => 'foo', + 'grant_type' => 'authorization_code', + 'redirect_uri' => 'http://bar/foo', + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'redirect_uri' => 'http://foo/bar', + ], JSON_THROW_ON_ERROR) + ), + ]); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -1221,29 +1076,19 @@ public function testRejectAccessTokenRequestIfRedirectUriSpecifiedButNotInOrigin $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'client_id' => 'foo', - 'grant_type' => 'authorization_code', - 'redirect_uri' => 'http://bar/foo', - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'redirect_uri' => null, - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'client_id' => 'foo', + 'grant_type' => 'authorization_code', + 'redirect_uri' => 'http://bar/foo', + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'redirect_uri' => null, + ], JSON_THROW_ON_ERROR) + ), + ]); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -1276,22 +1121,12 @@ public function testRespondToAccessTokenRequestMissingCode(): void $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'client_secret' => 'bar', - 'redirect_uri' => self::REDIRECT_URI, - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'client_secret' => 'bar', + 'redirect_uri' => self::REDIRECT_URI, + ]); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -1317,31 +1152,21 @@ public function testRespondToAccessTokenRequestWithRefreshTokenInsteadOfAuthCode $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'client_id' => 'foo', - 'refresh_token_id' => 'zyxwvu', - 'access_token_id' => 'abcdef', - 'scopes' => ['foo'], - 'user_id' => 123, - 'expire_time' => time() + 3600, - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'client_id' => 'foo', + 'refresh_token_id' => 'zyxwvu', + 'access_token_id' => 'abcdef', + 'scopes' => ['foo'], + 'user_id' => 123, + 'expire_time' => time() + 3600, + ], JSON_THROW_ON_ERROR) + ), + ]); try { /* @var StubResponseType $response */ @@ -1368,22 +1193,12 @@ public function testRespondToAccessTokenRequestWithAuthCodeNotAString(): void $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => ['not', 'a', 'string'], - ] - ); + $request = (new ServerRequest('', ''))->withQueryParams([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => ['not', 'a', 'string'], + ]); $this->expectException(OAuthServerException::class); $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -1406,31 +1221,21 @@ public function testRespondToAccessTokenRequestExpiredCode(): void $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() - 3600, - 'client_id' => 'foo', - 'user_id' => 123, - 'scopes' => ['foo'], - 'redirect_uri' => 'http://foo/bar', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() - 3600, + 'client_id' => 'foo', + 'user_id' => 123, + 'scopes' => ['foo'], + 'redirect_uri' => 'http://foo/bar', + ], JSON_THROW_ON_ERROR) + ), + ]); try { /* @var StubResponseType $response */ @@ -1472,31 +1277,21 @@ public function testRespondToAccessTokenRequestRevokedCode(): void $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => 123, - 'scopes' => ['foo'], - 'redirect_uri' => 'http://foo/bar', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => 123, + 'scopes' => ['foo'], + 'redirect_uri' => 'http://foo/bar', + ], JSON_THROW_ON_ERROR) + ), + ]); try { /* @var StubResponseType $response */ @@ -1536,31 +1331,21 @@ public function testRespondToAccessTokenRequestClientMismatch(): void $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'bar', - 'user_id' => 123, - 'scopes' => ['foo'], - 'redirect_uri' => 'http://foo/bar', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'bar', + 'user_id' => 123, + 'scopes' => ['foo'], + 'redirect_uri' => 'http://foo/bar', + ], JSON_THROW_ON_ERROR) + ), + ]); try { /* @var StubResponseType $response */ @@ -1599,22 +1384,12 @@ public function testRespondToAccessTokenRequestBadCodeEncryption(): void $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => 'sdfsfsd', - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => 'sdfsfsd', + ]); try { /* @var StubResponseType $response */ @@ -1662,34 +1437,24 @@ public function testRespondToAccessTokenRequestBadCodeVerifierPlain(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code_verifier' => self::CODE_VERIFIER, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - 'code_challenge' => 'foobar', - 'code_challenge_method' => 'plain', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code_verifier' => self::CODE_VERIFIER, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + 'code_challenge' => 'foobar', + 'code_challenge_method' => 'plain', + ], JSON_THROW_ON_ERROR) + ), + ]); try { /* @var StubResponseType $response */ @@ -1737,34 +1502,24 @@ public function testRespondToAccessTokenRequestBadCodeVerifierS256(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code_verifier' => 'nope', - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - 'code_challenge' => 'foobar', - 'code_challenge_method' => 'S256', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code_verifier' => 'nope', + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + 'code_challenge' => 'foobar', + 'code_challenge_method' => 'S256', + ], JSON_THROW_ON_ERROR) + ), + ]); try { /* @var StubResponseType $response */ @@ -1812,34 +1567,24 @@ public function testRespondToAccessTokenRequestMalformedCodeVerifierS256WithInva $grant->setScopeRepository($scopeRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code_verifier' => 'dqX7C-RbqjHYtytmhGTigKdZCXfxq-+xbsk9_GxUcaE', // Malformed code. Contains `+`. - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - 'code_challenge' => self::CODE_CHALLENGE, - 'code_challenge_method' => 'S256', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code_verifier' => 'dqX7C-RbqjHYtytmhGTigKdZCXfxq-+xbsk9_GxUcaE', // Malformed code. Contains `+`. + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + 'code_challenge' => self::CODE_CHALLENGE, + 'code_challenge_method' => 'S256', + ], JSON_THROW_ON_ERROR) + ), + ]); try { /* @var StubResponseType $response */ @@ -1887,34 +1632,24 @@ public function testRespondToAccessTokenRequestMalformedCodeVerifierS256WithInva $grant->setScopeRepository($scopeRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code_verifier' => 'dqX7C-RbqjHY', // Malformed code. Invalid length. - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - 'code_challenge' => 'R7T1y1HPNFvs1WDCrx4lfoBS6KD2c71pr8OHvULjvv8', - 'code_challenge_method' => 'S256', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code_verifier' => 'dqX7C-RbqjHY', // Malformed code. Invalid length. + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + 'code_challenge' => 'R7T1y1HPNFvs1WDCrx4lfoBS6KD2c71pr8OHvULjvv8', + 'code_challenge_method' => 'S256', + ], JSON_THROW_ON_ERROR) + ), + ]); try { /* @var StubResponseType $response */ @@ -1962,33 +1697,23 @@ public function testRespondToAccessTokenRequestMissingCodeVerifier(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - 'code_challenge' => 'foobar', - 'code_challenge_method' => 'plain', - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + 'code_challenge' => 'foobar', + 'code_challenge_method' => 'plain', + ], JSON_THROW_ON_ERROR) + ), + ]); try { /* @var StubResponseType $response */ @@ -2136,31 +1861,21 @@ public function testRefreshTokenRepositoryUniqueConstraintCheck(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + ], JSON_THROW_ON_ERROR) + ), + ]); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -2201,31 +1916,21 @@ public function testRefreshTokenRepositoryFailToPersist(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + ], JSON_THROW_ON_ERROR) + ), + ]); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(7); @@ -2269,31 +1974,21 @@ public function testRefreshTokenRepositoryFailToPersistUniqueNoInfiniteLoop(): v $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = new ServerRequest( - [], - [], - null, - 'POST', - 'php://input', - [], - [], - [], - [ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => $this->cryptStub->doEncrypt( - json_encode([ - 'auth_code_id' => uniqid(), - 'expire_time' => time() + 3600, - 'client_id' => 'foo', - 'user_id' => '123', - 'scopes' => ['foo'], - 'redirect_uri' => self::REDIRECT_URI, - ], JSON_THROW_ON_ERROR) - ), - ] - ); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => $this->cryptStub->doEncrypt( + json_encode([ + 'auth_code_id' => uniqid(), + 'expire_time' => time() + 3600, + 'client_id' => 'foo', + 'user_id' => '123', + 'scopes' => ['foo'], + 'redirect_uri' => self::REDIRECT_URI, + ], JSON_THROW_ON_ERROR) + ), + ]); $this->expectException(UniqueTokenIdentifierConstraintViolationException::class); $this->expectExceptionCode(100); @@ -2339,7 +2034,7 @@ public function testPublicClientAuthCodeRequestRejectedWhenCodeChallengeRequired $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => self::REDIRECT_URI, @@ -2373,20 +2068,11 @@ public function testUseValidRedirectUriIfScopeCheckFails(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = new ServerRequest( - [], - [], - null, - null, - 'php://input', - [], - [], - [ - 'response_type' => 'code', - 'client_id' => 'foo', - 'redirect_uri' => 'http://bar/foo', - ] - ); + $request = (new ServerRequest('', ''))->withQueryParams([ + 'response_type' => 'code', + 'client_id' => 'foo', + 'redirect_uri' => 'http://bar/foo', + ]); // At this point I need to validate the auth request try { diff --git a/tests/Grant/ClientCredentialsGrantTest.php b/tests/Grant/ClientCredentialsGrantTest.php index 69f756c37..b401db1ab 100644 --- a/tests/Grant/ClientCredentialsGrantTest.php +++ b/tests/Grant/ClientCredentialsGrantTest.php @@ -5,7 +5,6 @@ namespace LeagueTests\Grant; use DateInterval; -use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Grant\ClientCredentialsGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -15,6 +14,7 @@ use LeagueTests\Stubs\ClientEntity; use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\StubResponseType; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; class ClientCredentialsGrantTest extends TestCase @@ -53,7 +53,7 @@ public function testRespondToRequest(): void $grant->setDefaultScope(self::DEFAULT_SCOPE); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', ]); diff --git a/tests/Grant/DeviceCodeGrantTest.php b/tests/Grant/DeviceCodeGrantTest.php index 396ea760f..d9c902274 100644 --- a/tests/Grant/DeviceCodeGrantTest.php +++ b/tests/Grant/DeviceCodeGrantTest.php @@ -6,8 +6,6 @@ use DateInterval; use DateTimeImmutable; -use Laminas\Diactoros\Response; -use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; @@ -25,6 +23,8 @@ use LeagueTests\Stubs\RefreshTokenEntity; use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\StubResponseType; +use Nyholm\Psr7\Response; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; use function base64_encode; @@ -69,7 +69,7 @@ public function testCanRespondToDeviceAuthorizationRequest(): void 'http://foo/bar' ); - $request = (new ServerRequest())->withParsedBody([ + $request = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'scope' => 'basic', ]); @@ -105,7 +105,7 @@ public function testRespondToDeviceAuthorizationRequest(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setScopeRepository($scopeRepositoryMock); - $request = (new ServerRequest())->withParsedBody([ + $request = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'scope' => 'basic', ]); @@ -150,7 +150,7 @@ public function testRespondToDeviceAuthorizationRequestWithVerificationUriComple $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setScopeRepository($scopeRepositoryMock); - $request = (new ServerRequest())->withParsedBody([ + $request = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'scope' => 'basic', ]); @@ -189,7 +189,7 @@ public function testValidateDeviceAuthorizationRequestMissingClient(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest())->withParsedBody([ + $request = (new ServerRequest('', ''))->withParsedBody([ 'scope' => 'basic', ]); @@ -220,7 +220,7 @@ public function testValidateDeviceAuthorizationRequestEmptyScope(): void $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); - $request = (new ServerRequest())->withParsedBody([ + $request = (new ServerRequest('', ''))->withParsedBody([ 'scope' => '', ]); @@ -248,7 +248,7 @@ public function testValidateDeviceAuthorizationRequestClientMismatch(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest())->withParsedBody([ + $request = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'bar', 'scope' => 'basic', ]); @@ -313,7 +313,7 @@ public function testDeviceAuthorizationResponse(): void $server->setDefaultScope(self::DEFAULT_SCOPE); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', ]); @@ -386,7 +386,7 @@ public function testRespondToAccessTokenRequest(): void $grant->completeDeviceAuthorizationRequest($deviceCodeEntity->getUserCode(), '1', true); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'grant_type' => 'urn:ietf:params:oauth:grant-type:device_code', 'device_code' => $this->cryptStub->doEncrypt( json_encode( @@ -429,7 +429,7 @@ public function testRespondToRequestMissingClient(): void $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $serverRequest = (new ServerRequest())->withQueryParams([ + $serverRequest = (new ServerRequest('', ''))->withQueryParams([ 'device_code' => $this->cryptStub->doEncrypt( json_encode( [ @@ -487,7 +487,7 @@ public function testRespondToRequestMissingDeviceCode(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', ]); @@ -536,7 +536,7 @@ public function testIssueSlowDownError(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'device_code' => $this->cryptStub->doEncrypt( json_encode( @@ -597,7 +597,7 @@ public function testIssueAuthorizationPendingError(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'device_code' => $this->cryptStub->doEncrypt( json_encode( @@ -658,7 +658,7 @@ public function testIssueExpiredTokenError(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'device_code' => $this->cryptStub->doEncrypt( json_encode( @@ -715,7 +715,7 @@ public function testSettingDeviceCodeIntervalRate(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setIntervalVisibility(true); - $request = (new ServerRequest())->withParsedBody([ + $request = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'scope' => 'basic', ]); @@ -771,7 +771,7 @@ public function testIssueAccessDeniedError(): void $grant->completeDeviceAuthorizationRequest($deviceCode->getUserCode(), '1', false); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'device_code' => $this->cryptStub->doEncrypt( json_encode( diff --git a/tests/Grant/ImplicitGrantTest.php b/tests/Grant/ImplicitGrantTest.php index c2b943197..3119a9375 100644 --- a/tests/Grant/ImplicitGrantTest.php +++ b/tests/Grant/ImplicitGrantTest.php @@ -5,7 +5,6 @@ namespace LeagueTests\Grant; use DateInterval; -use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException; @@ -23,6 +22,7 @@ use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\UserEntity; use LogicException; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -49,7 +49,7 @@ public function testCanRespondToAccessTokenRequest(): void $grant = new ImplicitGrant(new DateInterval('PT10M')); self::assertFalse( - $grant->canRespondToAccessTokenRequest(new ServerRequest()) + $grant->canRespondToAccessTokenRequest(new ServerRequest('', '')) ); } @@ -60,7 +60,7 @@ public function testRespondToAccessTokenRequest(): void $this->expectException(LogicException::class); $grant->respondToAccessTokenRequest( - new ServerRequest(), + new ServerRequest('', ''), new StubResponseType(), new DateInterval('PT10M') ); @@ -70,7 +70,7 @@ public function testCanRespondToAuthorizationRequest(): void { $grant = new ImplicitGrant(new DateInterval('PT10M')); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'token', 'client_id' => 'foo', ]); @@ -94,7 +94,7 @@ public function testValidateAuthorizationRequest(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => self::REDIRECT_URI, @@ -119,7 +119,7 @@ public function testValidateAuthorizationRequestRedirectUriArray(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => self::REDIRECT_URI, @@ -135,7 +135,7 @@ public function testValidateAuthorizationRequestMissingClientId(): void $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setClientRepository($clientRepositoryMock); - $request = (new ServerRequest())->withQueryParams(['response_type' => 'code']); + $request = (new ServerRequest('', ''))->withQueryParams(['response_type' => 'code']); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -151,7 +151,7 @@ public function testValidateAuthorizationRequestInvalidClientId(): void $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setClientRepository($clientRepositoryMock); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', ]); @@ -172,7 +172,7 @@ public function testValidateAuthorizationRequestBadRedirectUriString(): void $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setClientRepository($clientRepositoryMock); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => 'http://bar', @@ -194,7 +194,7 @@ public function testValidateAuthorizationRequestBadRedirectUriArray(): void $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setClientRepository($clientRepositoryMock); - $request = (new ServerRequest())->withQueryParams([ + $request = (new ServerRequest('', ''))->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', 'redirect_uri' => 'http://bar', diff --git a/tests/Grant/PasswordGrantTest.php b/tests/Grant/PasswordGrantTest.php index 8c60a8c78..067721ef6 100644 --- a/tests/Grant/PasswordGrantTest.php +++ b/tests/Grant/PasswordGrantTest.php @@ -5,7 +5,6 @@ namespace LeagueTests\Grant; use DateInterval; -use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; @@ -21,6 +20,7 @@ use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\UserEntity; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; class PasswordGrantTest extends TestCase @@ -69,7 +69,7 @@ public function testRespondToRequest(): void $grant->setDefaultScope(self::DEFAULT_SCOPE); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'username' => 'foo', @@ -114,7 +114,7 @@ public function testRespondToRequestNullRefreshToken(): void $grant->setDefaultScope(self::DEFAULT_SCOPE); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'username' => 'foo', @@ -143,7 +143,7 @@ public function testRespondToRequestMissingUsername(): void $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $serverRequest = (new ServerRequest())->withQueryParams([ + $serverRequest = (new ServerRequest('', ''))->withQueryParams([ 'client_id' => 'foo', 'client_secret' => 'bar', ]); @@ -171,7 +171,7 @@ public function testRespondToRequestMissingPassword(): void $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'username' => 'alex', @@ -209,7 +209,7 @@ public function testRespondToRequestBadCredentials(): void $grant->setDefaultScope(self::DEFAULT_SCOPE); $grant->setScopeRepository($scopeRepositoryMock); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'username' => 'alex', diff --git a/tests/Grant/RefreshTokenGrantTest.php b/tests/Grant/RefreshTokenGrantTest.php index b37001a80..5ccd5c5fb 100644 --- a/tests/Grant/RefreshTokenGrantTest.php +++ b/tests/Grant/RefreshTokenGrantTest.php @@ -5,7 +5,6 @@ namespace LeagueTests\Grant; use DateInterval; -use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; @@ -20,6 +19,7 @@ use LeagueTests\Stubs\RefreshTokenEntity; use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\StubResponseType; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; use function json_encode; @@ -93,7 +93,7 @@ public function testRespondToRequest(): void $oldRefreshToken ); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $encryptedOldRefreshToken, @@ -157,7 +157,7 @@ public function testRespondToRequestNullRefreshToken(): void $oldRefreshToken ); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $encryptedOldRefreshToken, @@ -221,7 +221,7 @@ public function testRespondToReducedScopes(): void $oldRefreshToken ); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $encryptedOldRefreshToken, @@ -281,7 +281,7 @@ public function testRespondToUnexpectedScope(): void $oldRefreshToken ); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $encryptedOldRefreshToken, @@ -315,7 +315,7 @@ public function testRespondToRequestMissingOldToken(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', ]); @@ -349,7 +349,7 @@ public function testRespondToRequestInvalidOldToken(): void $oldRefreshToken = 'foobar'; - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $oldRefreshToken, @@ -404,7 +404,7 @@ public function testRespondToRequestClientMismatch(): void $oldRefreshToken ); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $encryptedOldRefreshToken, @@ -456,7 +456,7 @@ public function testRespondToRequestExpiredToken(): void $oldRefreshToken ); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $encryptedOldRefreshToken, @@ -509,7 +509,7 @@ public function testRespondToRequestRevokedToken(): void $oldRefreshToken ); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $encryptedOldRefreshToken, @@ -591,7 +591,7 @@ public function testRespondToRequestFinalizeScopes(): void $oldRefreshToken ); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $encryptedOldRefreshToken, @@ -650,7 +650,7 @@ public function testRevokedRefreshToken(): void $oldRefreshToken ); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $encryptedOldRefreshToken, @@ -715,7 +715,7 @@ public function testUnrevokedRefreshToken(): void $oldRefreshToken ); - $serverRequest = (new ServerRequest())->withParsedBody([ + $serverRequest = (new ServerRequest('', ''))->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $encryptedOldRefreshToken, diff --git a/tests/Middleware/AuthorizationServerMiddlewareTest.php b/tests/Middleware/AuthorizationServerMiddlewareTest.php index 814e96a6c..d3bedef5f 100644 --- a/tests/Middleware/AuthorizationServerMiddlewareTest.php +++ b/tests/Middleware/AuthorizationServerMiddlewareTest.php @@ -5,8 +5,6 @@ namespace LeagueTests\Middleware; use DateInterval; -use Laminas\Diactoros\Response; -use Laminas\Diactoros\ServerRequestFactory; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\ClientCredentialsGrant; @@ -18,6 +16,8 @@ use LeagueTests\Stubs\ClientEntity; use LeagueTests\Stubs\ScopeEntity; use LeagueTests\Stubs\StubResponseType; +use Nyholm\Psr7\Response; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; use function base64_encode; @@ -58,11 +58,11 @@ public function testValidResponse(): void $server->setDefaultScope(self::DEFAULT_SCOPE); $server->enableGrantType(new ClientCredentialsGrant()); - $_POST['grant_type'] = 'client_credentials'; - $_POST['client_id'] = 'foo'; - $_POST['client_secret'] = 'bar'; - - $request = ServerRequestFactory::fromGlobals(); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'client_credentials', + 'client_id' => 'foo', + 'client_secret' => 'bar', + ]); $middleware = new AuthorizationServerMiddleware($server); $response = $middleware->__invoke( @@ -91,11 +91,11 @@ public function testOAuthErrorResponse(): void $server->enableGrantType(new ClientCredentialsGrant(), new DateInterval('PT1M')); - $_POST['grant_type'] = 'client_credentials'; - $_POST['client_id'] = 'foo'; - $_POST['client_secret'] = 'bar'; - - $request = ServerRequestFactory::fromGlobals(); + $request = (new ServerRequest('', ''))->withParsedBody([ + 'grant_type' => 'client_credentials', + 'client_id' => 'foo', + 'client_secret' => 'bar', + ]); $middleware = new AuthorizationServerMiddleware($server); diff --git a/tests/Middleware/ResourceServerMiddlewareTest.php b/tests/Middleware/ResourceServerMiddlewareTest.php index 4a6d3b79e..8edf54670 100644 --- a/tests/Middleware/ResourceServerMiddlewareTest.php +++ b/tests/Middleware/ResourceServerMiddlewareTest.php @@ -6,14 +6,14 @@ use DateInterval; use DateTimeImmutable; -use Laminas\Diactoros\Response; -use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Middleware\ResourceServerMiddleware; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\ResourceServer; use LeagueTests\Stubs\AccessTokenEntity; use LeagueTests\Stubs\ClientEntity; +use Nyholm\Psr7\Response; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; use function func_get_args; @@ -40,7 +40,7 @@ public function testValidResponse(): void $token = $accessToken->toString(); - $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $token)); + $request = (new ServerRequest('', ''))->withHeader('authorization', sprintf('Bearer %s', $token)); $middleware = new ResourceServerMiddleware($server); $response = $middleware->__invoke( @@ -75,7 +75,7 @@ public function testValidResponseExpiredToken(): void $token = $accessToken->toString(); - $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $token)); + $request = (new ServerRequest('', ''))->withHeader('authorization', sprintf('Bearer %s', $token)); $middleware = new ResourceServerMiddleware($server); $response = $middleware->__invoke( @@ -98,7 +98,7 @@ public function testErrorResponse(): void 'file://' . __DIR__ . '/../Stubs/public.key' ); - $request = (new ServerRequest())->withHeader('authorization', ''); + $request = (new ServerRequest('', ''))->withHeader('authorization', ''); $middleware = new ResourceServerMiddleware($server); $response = $middleware->__invoke( diff --git a/tests/ResourceServerTest.php b/tests/ResourceServerTest.php index 41ac2e854..8954a7af2 100644 --- a/tests/ResourceServerTest.php +++ b/tests/ResourceServerTest.php @@ -4,10 +4,10 @@ namespace LeagueTests; -use Laminas\Diactoros\ServerRequestFactory; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\ResourceServer; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; class ResourceServerTest extends TestCase @@ -20,7 +20,7 @@ public function testValidateAuthenticatedRequest(): void ); try { - $server->validateAuthenticatedRequest(ServerRequestFactory::fromGlobals()); + $server->validateAuthenticatedRequest(new ServerRequest('', '')); } catch (OAuthServerException $e) { self::assertEquals('Missing "Authorization" header', $e->getHint()); } diff --git a/tests/ResponseTypes/BearerResponseTypeTest.php b/tests/ResponseTypes/BearerResponseTypeTest.php index 386fb628b..05911a6c8 100644 --- a/tests/ResponseTypes/BearerResponseTypeTest.php +++ b/tests/ResponseTypes/BearerResponseTypeTest.php @@ -6,8 +6,6 @@ use DateInterval; use DateTimeImmutable; -use Laminas\Diactoros\Response; -use Laminas\Diactoros\ServerRequest; use League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Exception\OAuthServerException; @@ -17,6 +15,8 @@ use LeagueTests\Stubs\ClientEntity; use LeagueTests\Stubs\RefreshTokenEntity; use LeagueTests\Stubs\ScopeEntity; +use Nyholm\Psr7\Response; +use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\TestCase; use function base64_encode; @@ -148,7 +148,7 @@ public function testDetermineAccessTokenInHeaderValidToken(): void $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); - $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); + $request = (new ServerRequest('', ''))->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); $request = $authorizationValidator->validateAuthorization($request); @@ -190,7 +190,7 @@ public function testDetermineAccessTokenInHeaderInvalidJWT(): void $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); - $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); + $request = (new ServerRequest('', ''))->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); try { $authorizationValidator->validateAuthorization($request); @@ -235,7 +235,7 @@ public function testDetermineAccessTokenInHeaderRevokedToken(): void $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); - $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); + $request = (new ServerRequest('', ''))->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); try { $authorizationValidator->validateAuthorization($request); @@ -258,7 +258,7 @@ public function testDetermineAccessTokenInHeaderInvalidToken(): void $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); - $request = (new ServerRequest())->withHeader('authorization', 'Bearer blah'); + $request = (new ServerRequest('', ''))->withHeader('authorization', 'Bearer blah'); try { $authorizationValidator->validateAuthorization($request); @@ -281,7 +281,7 @@ public function testDetermineMissingBearerInHeader(): void $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); - $request = (new ServerRequest())->withHeader('authorization', 'Bearer blah.blah.blah'); + $request = (new ServerRequest('', ''))->withHeader('authorization', 'Bearer blah.blah.blah'); try { $authorizationValidator->validateAuthorization($request); diff --git a/tests/ResponseTypes/DeviceCodeResponseTypeTest.php b/tests/ResponseTypes/DeviceCodeResponseTypeTest.php index 93bd9d6b3..a8db43a8b 100644 --- a/tests/ResponseTypes/DeviceCodeResponseTypeTest.php +++ b/tests/ResponseTypes/DeviceCodeResponseTypeTest.php @@ -6,12 +6,12 @@ use DateInterval; use DateTimeImmutable; -use Laminas\Diactoros\Response; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\ResponseTypes\DeviceCodeResponse; use LeagueTests\Stubs\ClientEntity; use LeagueTests\Stubs\DeviceCodeEntity; use LeagueTests\Stubs\ScopeEntity; +use Nyholm\Psr7\Response; use PHPUnit\Framework\TestCase; use function base64_encode; diff --git a/tests/Stubs/StubResponseType.php b/tests/Stubs/StubResponseType.php index 02f6f14e8..dcbab5043 100644 --- a/tests/Stubs/StubResponseType.php +++ b/tests/Stubs/StubResponseType.php @@ -4,11 +4,11 @@ namespace LeagueTests\Stubs; -use Laminas\Diactoros\Response; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\ResponseTypes\AbstractResponseType; +use Nyholm\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface;