From cc52256b4c4fcc01f8fbf294a16b70298e147f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Wed, 4 Sep 2024 12:36:43 +0200 Subject: [PATCH 1/8] Add PHP 8.4 support --- .github/workflows/static-analysis.yml | 2 +- .github/workflows/tests.yml | 2 +- composer.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index c6c01d4ea..063e3f875 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - php-version: [8.1, 8.2, 8.3] + php-version: [8.1, 8.2, 8.3, 8.4] composer-stability: [prefer-lowest, prefer-stable] operating-system: - ubuntu-latest diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7090fce13..0d76a2fa1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php: [8.1, 8.2, 8.3] + php: [8.1, 8.2, 8.3, 8.4] os: [ubuntu-22.04] stability: [prefer-lowest, prefer-stable] diff --git a/composer.json b/composer.json index 9376506a2..063ef0cc4 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "homepage": "https://oauth2.thephpleague.com/", "license": "MIT", "require": { - "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", "ext-openssl": "*", "league/event": "^3.0", "league/uri": "^7.0", From 9b99c22c64189da397fb5e5b41033ce679c6589d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Wed, 4 Sep 2024 12:34:48 +0200 Subject: [PATCH 2/8] Fix `Implicitly marking parameter $param as nullable is deprecated` --- phpcs.xml.dist | 1 + src/Exception/OAuthServerException.php | 16 ++++++++-------- src/Grant/AbstractGrant.php | 2 +- src/ResourceServer.php | 6 +----- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6e471456d..b7b0aa4d6 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -33,4 +33,5 @@ + diff --git a/src/Exception/OAuthServerException.php b/src/Exception/OAuthServerException.php index 9eff92456..24a38d3fe 100644 --- a/src/Exception/OAuthServerException.php +++ b/src/Exception/OAuthServerException.php @@ -33,7 +33,7 @@ class OAuthServerException extends Exception /** * Throw a new exception. */ - final public function __construct(string $message, int $code, private string $errorType, private int $httpStatusCode = 400, private ?string $hint = null, private ?string $redirectUri = null, Throwable $previous = null) + final public function __construct(string $message, int $code, private string $errorType, private int $httpStatusCode = 400, private ?string $hint = null, private ?string $redirectUri = null, ?Throwable $previous = null) { parent::__construct($message, $code, $previous); $this->payload = [ @@ -88,7 +88,7 @@ public static function unsupportedGrantType(): static /** * Invalid request error. */ - public static function invalidRequest(string $parameter, ?string $hint = null, Throwable $previous = null): static + public static function invalidRequest(string $parameter, ?string $hint = null, ?Throwable $previous = null): static { $errorMessage = 'The request is missing a required parameter, includes an invalid parameter value, ' . 'includes a parameter more than once, or is otherwise malformed.'; @@ -141,7 +141,7 @@ public static function invalidCredentials(): static * * @codeCoverageIgnore */ - public static function serverError(string $hint, Throwable $previous = null): static + public static function serverError(string $hint, ?Throwable $previous = null): static { return new static( 'The authorization server encountered an unexpected condition which prevented it from fulfilling' @@ -158,7 +158,7 @@ public static function serverError(string $hint, Throwable $previous = null): st /** * Invalid refresh token. */ - public static function invalidRefreshToken(?string $hint = null, Throwable $previous = null): static + public static function invalidRefreshToken(?string $hint = null, ?Throwable $previous = null): static { return new static('The refresh token is invalid.', 8, 'invalid_grant', 400, $hint, null, $previous); } @@ -166,7 +166,7 @@ public static function invalidRefreshToken(?string $hint = null, Throwable $prev /** * Access denied. */ - public static function accessDenied(?string $hint = null, ?string $redirectUri = null, Throwable $previous = null): static + public static function accessDenied(?string $hint = null, ?string $redirectUri = null, ?Throwable $previous = null): static { return new static( 'The resource owner or authorization server denied the request.', @@ -207,7 +207,7 @@ public function getErrorType(): string * * @return static */ - public static function expiredToken(?string $hint = null, Throwable $previous = null): static + public static function expiredToken(?string $hint = null, ?Throwable $previous = null): static { $errorMessage = 'The `device_code` has expired and the device ' . 'authorization session has concluded.'; @@ -215,7 +215,7 @@ public static function expiredToken(?string $hint = null, Throwable $previous = return new static($errorMessage, 11, 'expired_token', 400, $hint, null, $previous); } - public static function authorizationPending(string $hint = '', Throwable $previous = null): static + public static function authorizationPending(string $hint = '', ?Throwable $previous = null): static { return new static( 'The authorization request is still pending as the end user ' . @@ -236,7 +236,7 @@ public static function authorizationPending(string $hint = '', Throwable $previo * * @return static */ - public static function slowDown(string $hint = '', Throwable $previous = null): static + public static function slowDown(string $hint = '', ?Throwable $previous = null): static { return new static( 'The authorization request is still pending and polling should ' . diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index ea0064c3b..5ab81ff77 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -243,7 +243,7 @@ protected function validateRedirectUri( * * @return ScopeEntityInterface[] */ - public function validateScopes(string|array|null $scopes, string $redirectUri = null): array + public function validateScopes(string|array|null $scopes, ?string $redirectUri = null): array { if ($scopes === null) { $scopes = []; diff --git a/src/ResourceServer.php b/src/ResourceServer.php index e89e8d24a..102466fd6 100644 --- a/src/ResourceServer.php +++ b/src/ResourceServer.php @@ -22,19 +22,15 @@ class ResourceServer { private CryptKeyInterface $publicKey; - private ?AuthorizationValidatorInterface $authorizationValidator = null; - public function __construct( private AccessTokenRepositoryInterface $accessTokenRepository, CryptKeyInterface|string $publicKey, - AuthorizationValidatorInterface $authorizationValidator = null + private ?AuthorizationValidatorInterface $authorizationValidator = null ) { if ($publicKey instanceof CryptKeyInterface === false) { $publicKey = new CryptKey($publicKey); } $this->publicKey = $publicKey; - - $this->authorizationValidator = $authorizationValidator; } protected function getAuthorizationValidator(): AuthorizationValidatorInterface From fce9b7456e0b16b2496cf01c02fa6eded3e7a7f1 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 11 Oct 2024 22:29:16 +0330 Subject: [PATCH 3/8] replace `laminas/laminas-diactoros` with `nyholm/psr7` --- composer.json | 2 +- examples/composer.json | 8 +- examples/composer.lock | 310 ++--- examples/public/auth_code.php | 8 +- examples/public/client_credentials.php | 5 +- examples/public/implicit.php | 4 +- examples/public/middleware_use.php | 4 +- tests/AuthorizationServerTest.php | 37 +- .../BearerTokenValidatorTest.php | 11 +- tests/Exception/OAuthServerExceptionTest.php | 12 +- tests/Grant/AbstractGrantTest.php | 60 +- tests/Grant/AuthCodeGrantTest.php | 1130 ++++++----------- tests/Grant/ClientCredentialsGrantTest.php | 4 +- tests/Grant/DeviceCodeGrantTest.php | 34 +- tests/Grant/ImplicitGrantTest.php | 20 +- tests/Grant/PasswordGrantTest.php | 12 +- tests/Grant/RefreshTokenGrantTest.php | 26 +- .../AuthorizationServerMiddlewareTest.php | 24 +- .../ResourceServerMiddlewareTest.php | 10 +- tests/ResourceServerTest.php | 4 +- .../ResponseTypes/BearerResponseTypeTest.php | 14 +- .../DeviceCodeResponseTypeTest.php | 2 +- tests/Stubs/StubResponseType.php | 2 +- 23 files changed, 660 insertions(+), 1083 deletions(-) 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; From cdbae0dbbde674fccef75ea9693c965964cd0e4d Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 11 Oct 2024 22:47:33 +0330 Subject: [PATCH 4/8] update dependencies --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 509f5ebfb..6101acfd6 100644 --- a/composer.json +++ b/composer.json @@ -16,9 +16,9 @@ "psr/http-server-middleware": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^9.6.15", + "phpunit/phpunit": "^9.6.21", "nyholm/psr7": "^1.8", - "phpstan/phpstan": "^1.10.55", + "phpstan/phpstan": "^1.12", "phpstan/phpstan-phpunit": "^1.3.15", "roave/security-advisories": "dev-master", "phpstan/extension-installer": "^1.3.1", From 9b6045db186f4c67770cc08135eb5c2110f82d51 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Sat, 12 Oct 2024 15:12:35 +0330 Subject: [PATCH 5/8] fix tests --- tests/Grant/AuthCodeGrantTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Grant/AuthCodeGrantTest.php b/tests/Grant/AuthCodeGrantTest.php index 49a64e90f..b2e778afd 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -446,7 +446,7 @@ public function testValidateAuthorizationRequestInvalidScopes(): 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, From 7fb4cba095ef28e61ced1e1b205916a27d234d20 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Tue, 15 Oct 2024 02:25:23 +0330 Subject: [PATCH 6/8] Revert "fix tests" This reverts commit 9b6045db186f4c67770cc08135eb5c2110f82d51. --- tests/Grant/AuthCodeGrantTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Grant/AuthCodeGrantTest.php b/tests/Grant/AuthCodeGrantTest.php index b2e778afd..49a64e90f 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -446,7 +446,7 @@ public function testValidateAuthorizationRequestInvalidScopes(): 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, From 71299658ea44161a7228895658bc36f38b66bd83 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Tue, 15 Oct 2024 02:32:07 +0330 Subject: [PATCH 7/8] revert "replace `laminas/laminas-diactoros` with `nyholm/psr7`" --- composer.json | 2 +- examples/composer.json | 8 +- examples/composer.lock | 310 +++-- examples/public/auth_code.php | 8 +- examples/public/client_credentials.php | 5 +- examples/public/implicit.php | 4 +- examples/public/middleware_use.php | 4 +- tests/AuthorizationServerTest.php | 37 +- .../BearerTokenValidatorTest.php | 11 +- tests/Exception/OAuthServerExceptionTest.php | 12 +- tests/Grant/AbstractGrantTest.php | 60 +- tests/Grant/AuthCodeGrantTest.php | 1130 +++++++++++------ tests/Grant/ClientCredentialsGrantTest.php | 4 +- tests/Grant/DeviceCodeGrantTest.php | 34 +- tests/Grant/ImplicitGrantTest.php | 22 +- tests/Grant/PasswordGrantTest.php | 12 +- tests/Grant/RefreshTokenGrantTest.php | 26 +- .../AuthorizationServerMiddlewareTest.php | 24 +- .../ResourceServerMiddlewareTest.php | 10 +- tests/ResourceServerTest.php | 4 +- .../ResponseTypes/BearerResponseTypeTest.php | 14 +- .../DeviceCodeResponseTypeTest.php | 2 +- tests/Stubs/StubResponseType.php | 2 +- 23 files changed, 1084 insertions(+), 661 deletions(-) diff --git a/composer.json b/composer.json index 6101acfd6..9c81075eb 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require-dev": { "phpunit/phpunit": "^9.6.21", - "nyholm/psr7": "^1.8", + "laminas/laminas-diactoros": "^3.5", "phpstan/phpstan": "^1.12", "phpstan/phpstan-phpunit": "^1.3.15", "roave/security-advisories": "dev-master", diff --git a/examples/composer.json b/examples/composer.json index 8776a9551..7d2000be5 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 || ^5.0", - "psr/http-message": "^1.1 || ^2.0", - "defuse/php-encryption": "^2.4", - "nyholm/psr7": "^1.8" + "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" }, "autoload": { "psr-4": { diff --git a/examples/composer.lock b/examples/composer.lock index ae308fed1..58f1c60cb 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": "b2041830e6c4a6fadd7f9c9a57c86591", + "content-hash": "ac8c2c0c3717f72036b55ab34445a89d", "packages": [ { "name": "nikic/fast-route", @@ -366,40 +366,202 @@ }, "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": "5.4.0", + "version": "4.3.0", "source": { "type": "git", "url": "https://github.com/lcobucci/jwt.git", - "reference": "aac4fd512681fd5cb4b77d2105ab7ec700c72051" + "reference": "4d7de2fe0d51a96418c0d04004986e410e87f6b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/lcobucci/jwt/zipball/aac4fd512681fd5cb4b77d2105ab7ec700c72051", - "reference": "aac4fd512681fd5cb4b77d2105ab7ec700c72051", + "url": "https://api.github.com/repos/lcobucci/jwt/zipball/4d7de2fe0d51a96418c0d04004986e410e87f6b4", + "reference": "4d7de2fe0d51a96418c0d04004986e410e87f6b4", "shasum": "" }, "require": { + "ext-hash": "*", + "ext-json": "*", + "ext-mbstring": "*", "ext-openssl": "*", "ext-sodium": "*", - "php": "~8.2.0 || ~8.3.0 || ~8.4.0", - "psr/clock": "^1.0" + "lcobucci/clock": "^2.0 || ^3.0", + "php": "^7.4 || ^8.0" }, "require-dev": { - "infection/infection": "^0.29", - "lcobucci/clock": "^3.2", - "lcobucci/coding-standard": "^11.0", + "infection/infection": "^0.21", + "lcobucci/coding-standard": "^6.0", + "mikey179/vfsstream": "^1.6.7", "phpbench/phpbench": "^1.2", - "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" + "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" }, "type": "library", "autoload": { @@ -425,7 +587,7 @@ ], "support": { "issues": "https://github.com/lcobucci/jwt/issues", - "source": "https://github.com/lcobucci/jwt/tree/5.4.0" + "source": "https://github.com/lcobucci/jwt/tree/4.3.0" }, "funding": [ { @@ -437,20 +599,20 @@ "type": "patreon" } ], - "time": "2024-10-08T22:06:45+00:00" + "time": "2023-01-02T13:28:00+00:00" }, { "name": "league/event", - "version": "3.0.3", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/thephpleague/event.git", - "reference": "ec38ff7ea10cad7d99a79ac937fbcffb9334c210" + "reference": "221867a61087ee265ca07bd39aa757879afca820" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/event/zipball/ec38ff7ea10cad7d99a79ac937fbcffb9334c210", - "reference": "ec38ff7ea10cad7d99a79ac937fbcffb9334c210", + "url": "https://api.github.com/repos/thephpleague/event/zipball/221867a61087ee265ca07bd39aa757879afca820", + "reference": "221867a61087ee265ca07bd39aa757879afca820", "shasum": "" }, "require": { @@ -494,87 +656,9 @@ ], "support": { "issues": "https://github.com/thephpleague/event/issues", - "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" + "source": "https://github.com/thephpleague/event/tree/3.0.2" }, - "funding": [ - { - "url": "https://github.com/Zegnat", - "type": "github" - }, - { - "url": "https://github.com/nyholm", - "type": "github" - } - ], - "time": "2024-09-09T07:06:30+00:00" + "time": "2022-10-29T09:31:25+00:00" }, { "name": "paragonie/random_compat", @@ -726,20 +810,20 @@ }, { "name": "psr/http-factory", - "version": "1.1.0", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/php-fig/http-factory.git", - "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" + "reference": "e616d01114759c4c489f93b099585439f795fe35" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", - "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", + "reference": "e616d01114759c4c489f93b099585439f795fe35", "shasum": "" }, "require": { - "php": ">=7.1", + "php": ">=7.0.0", "psr/http-message": "^1.0 || ^2.0" }, "type": "library", @@ -763,7 +847,7 @@ "homepage": "https://www.php-fig.org/" } ], - "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", + "description": "Common interfaces for PSR-7 HTTP message factories", "keywords": [ "factory", "http", @@ -775,9 +859,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-factory" + "source": "https://github.com/php-fig/http-factory/tree/1.0.2" }, - "time": "2024-04-15T12:06:14+00:00" + "time": "2023-04-10T20:10:41+00:00" } ], "aliases": [], diff --git a/examples/public/auth_code.php b/examples/public/auth_code.php index 1a2fa118d..815d86dee 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,7 +84,8 @@ } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); } catch (Exception $exception) { - $body = Stream::create($exception->getMessage()); + $body = new Stream('php://temp', 'r+'); + $body->write($exception->getMessage()); return $response->withStatus(500)->withBody($body); } @@ -99,7 +100,8 @@ } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); } catch (Exception $exception) { - $body = Stream::create($exception->getMessage()); + $body = new Stream('php://temp', 'r+'); + $body->write($exception->getMessage()); return $response->withStatus(500)->withBody($body); } diff --git a/examples/public/client_credentials.php b/examples/public/client_credentials.php index 113ebcbc2..080b06e07 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,7 +68,8 @@ return $exception->generateHttpResponse($response); } catch (Exception $exception) { // Unknown exception - $body = Stream::create($exception->getMessage()); + $body = new Stream('php://temp', 'r+'); + $body->write($exception->getMessage()); return $response->withStatus(500)->withBody($body); } diff --git a/examples/public/implicit.php b/examples/public/implicit.php index f12f80f69..6c54b8f2c 100644 --- a/examples/public/implicit.php +++ b/examples/public/implicit.php @@ -10,6 +10,7 @@ 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; @@ -72,7 +73,8 @@ } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); } catch (Exception $exception) { - $body = Stream::create($exception->getMessage()); + $body = new Stream('php://temp', 'r+'); + $body->write($exception->getMessage()); return $response->withStatus(500)->withBody($body); } diff --git a/examples/public/middleware_use.php b/examples/public/middleware_use.php index 688e2fa21..49bb5b5bb 100644 --- a/examples/public/middleware_use.php +++ b/examples/public/middleware_use.php @@ -12,6 +12,7 @@ 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; @@ -101,7 +102,8 @@ $params['email'] = 'alex@example.com'; } - $body = Stream::create(json_encode($params)); + $body = new Stream('php://temp', 'r+'); + $body->write(json_encode($params)); return $response->withBody($body); }); diff --git a/tests/AuthorizationServerTest.php b/tests/AuthorizationServerTest.php index 42d0b3d05..6e41a17f3 100644 --- a/tests/AuthorizationServerTest.php +++ b/tests/AuthorizationServerTest.php @@ -6,6 +6,9 @@ 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; @@ -25,8 +28,6 @@ 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; @@ -80,7 +81,7 @@ public function testRespondToRequestInvalidGrantType(): void $server->enableGrantType(new ClientCredentialsGrant(), new DateInterval('PT1M')); try { - $server->respondToAccessTokenRequest(new ServerRequest('', ''), new Response()); + $server->respondToAccessTokenRequest(ServerRequestFactory::fromGlobals(), new Response()); } catch (OAuthServerException $e) { self::assertEquals('unsupported_grant_type', $e->getErrorType()); self::assertEquals(400, $e->getHttpStatusCode()); @@ -118,13 +119,10 @@ public function testRespondToRequest(): void $server->setDefaultScope(self::DEFAULT_SCOPE); $server->enableGrantType(new ClientCredentialsGrant(), new DateInterval('PT1M')); - $request = (new ServerRequest('', ''))->withParsedBody([ - 'grant_type' => 'client_credentials', - 'client_id' => 'foo', - 'client_secret' => 'bar', - ]); - - $response = $server->respondToAccessTokenRequest($request, new Response()); + $_POST['grant_type'] = 'client_credentials'; + $_POST['client_id'] = 'foo'; + $_POST['client_secret'] = 'bar'; + $response = $server->respondToAccessTokenRequest(ServerRequestFactory::fromGlobals(), new Response()); self::assertEquals(200, $response->getStatusCode()); } @@ -302,10 +300,19 @@ public function testValidateAuthorizationRequest(): void $server->setDefaultScope(self::DEFAULT_SCOPE); $server->enableGrantType($grant); - $request = (new ServerRequest('', ''))->withQueryParams([ - 'response_type' => 'code', - 'client_id' => 'foo', - ]); + $request = new ServerRequest( + [], + [], + null, + null, + 'php://input', + $headers = [], + $cookies = [], + $queryParams = [ + 'response_type' => 'code', + 'client_id' => 'foo', + ] + ); self::assertInstanceOf(AuthorizationRequest::class, $server->validateAuthorizationRequest($request)); } @@ -320,7 +327,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 d041cf5cd..148473eea 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,6 +89,7 @@ public function testBearerTokenValidatorAcceptsExpiredTokenWithinLeeway(): void $bearerTokenValidatorReflection = new ReflectionClass(BearerTokenValidator::class); $jwtConfiguration = $bearerTokenValidatorReflection->getProperty('jwtConfiguration'); + $jwtConfiguration->setAccessible(true); $jwtTokenFromFutureWithinLeeway = $jwtConfiguration->getValue($bearerTokenValidator)->builder() ->permittedFor('client-id') @@ -100,7 +101,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); @@ -131,7 +132,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 51c7d227d..93db59f2a 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 9f1ddc407..adfb880be 100644 --- a/tests/Grant/AbstractGrantTest.php +++ b/tests/Grant/AbstractGrantTest.php @@ -5,6 +5,7 @@ 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; @@ -23,7 +24,6 @@ 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,10 +119,20 @@ public function testGetClientCredentialsClientSecretNotAString(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest('', ''))->withQueryParams([ - 'client_id' => 'client_id', - 'client_secret' => ['not', 'a', 'string'], - ]); + $serverRequest = new ServerRequest( + [], + [], + null, + 'POST', + 'php://input', + [], + [], + [], + [ + 'client_id' => 'client_id', + 'client_secret' => ['not', 'a', 'string'], + ] + ); $getClientCredentialsMethod = $abstractGrantReflection->getMethod('getClientCredentials'); $getClientCredentialsMethod->setAccessible(true); @@ -147,7 +157,7 @@ public function testValidateClientPublic(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest('', ''))->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', ]); @@ -174,7 +184,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', @@ -199,7 +209,7 @@ public function testValidateClientMissingClientId(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = new ServerRequest('', ''); + $serverRequest = new ServerRequest(); $validateClientMethod = $abstractGrantReflection->getMethod('validateClient'); $validateClientMethod->setAccessible(true); @@ -219,7 +229,7 @@ public function testValidateClientMissingClientSecret(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest('', ''))->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', ]); @@ -242,7 +252,7 @@ public function testValidateClientInvalidClientSecret(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest('', ''))->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'foo', ]); @@ -268,7 +278,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', ]); @@ -294,7 +304,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', ]); @@ -320,7 +330,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'], ]); @@ -344,7 +354,7 @@ public function testValidateClientBadClient(): void $abstractGrantReflection = new ReflectionClass($grantMock); - $serverRequest = (new ServerRequest('', ''))->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', ]); @@ -363,7 +373,7 @@ public function testCanRespondToRequest(): void $grantMock->method('getIdentifier')->willReturn('foobar'); $grantMock->setDefaultScope('defaultScope'); - $serverRequest = (new ServerRequest('', ''))->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'grant_type' => 'foobar', ]); @@ -480,7 +490,7 @@ public function testGetCookieParameter(): void $method = $abstractGrantReflection->getMethod('getCookieParameter'); $method->setAccessible(true); - $serverRequest = (new ServerRequest('', ''))->withCookieParams([ + $serverRequest = (new ServerRequest())->withCookieParams([ 'foo' => 'bar', ]); @@ -497,7 +507,7 @@ public function testGetQueryStringParameter(): void $method = $abstractGrantReflection->getMethod('getQueryStringParameter'); $method->setAccessible(true); - $serverRequest = (new ServerRequest('', ''))->withQueryParams([ + $serverRequest = (new ServerRequest())->withQueryParams([ 'foo' => 'bar', ]); @@ -546,7 +556,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 @@ -555,7 +565,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 49a64e90f..646056618 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -5,6 +5,8 @@ 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; @@ -26,8 +28,6 @@ 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,10 +70,19 @@ public function testCanRespondToAuthorizationRequest(): void new DateInterval('PT10M') ); - $request = (new ServerRequest('', ''))->withQueryParams([ - 'response_type' => 'code', - 'client_id' => 'foo', - ]); + $request = new ServerRequest( + [], + [], + null, + null, + 'php://input', + $headers = [], + $cookies = [], + $queryParams = [ + 'response_type' => 'code', + 'client_id' => 'foo', + ] + ); self::assertTrue($grant->canRespondToAuthorizationRequest($request)); } @@ -100,11 +109,20 @@ public function testValidateAuthorizationRequest(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest('', ''))->withQueryParams([ - 'response_type' => 'code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - ]); + $request = new ServerRequest( + [], + [], + null, + null, + 'php://input', + [], + [], + [ + 'response_type' => 'code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + ] + ); self::assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request)); } @@ -130,11 +148,20 @@ public function testValidateAuthorizationRequestRedirectUriArray(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest('', ''))->withQueryParams([ - 'response_type' => 'code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - ]); + $request = new ServerRequest( + [], + [], + null, + null, + 'php://input', + [], + [], + [ + 'response_type' => 'code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + ] + ); self::assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request)); } @@ -161,10 +188,19 @@ public function testValidateAuthorizationRequestWithoutRedirectUri(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest('', ''))->withQueryParams([ - 'response_type' => 'code', - 'client_id' => 'foo', - ]); + $request = new ServerRequest( + [], + [], + null, + null, + 'php://input', + [], + [], + [ + 'response_type' => 'code', + 'client_id' => 'foo', + ] + ); $authorizationRequest = $grant->validateAuthorizationRequest($request); self::assertInstanceOf(AuthorizationRequest::class, $authorizationRequest); @@ -193,12 +229,21 @@ public function testValidateAuthorizationRequestCodeChallenge(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest('', ''))->withQueryParams([ - 'response_type' => 'code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code_challenge' => self::CODE_CHALLENGE, - ]); + $request = new ServerRequest( + [], + [], + null, + null, + 'php://input', + [], + [], + [ + 'response_type' => 'code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code_challenge' => self::CODE_CHALLENGE, + ] + ); self::assertInstanceOf(AuthorizationRequest::class, $grant->validateAuthorizationRequest($request)); } @@ -221,7 +266,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, @@ -251,7 +296,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, @@ -281,7 +326,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, @@ -304,7 +349,7 @@ public function testValidateAuthorizationRequestMissingClientId(): void ); $grant->setClientRepository($clientRepositoryMock); - $request = (new ServerRequest('', ''))->withQueryParams([ + $request = (new ServerRequest())->withQueryParams([ 'response_type' => 'code', ]); @@ -326,7 +371,7 @@ public function testValidateAuthorizationRequestInvalidClientId(): void ); $grant->setClientRepository($clientRepositoryMock); - $request = (new ServerRequest('', ''))->withQueryParams([ + $request = (new ServerRequest())->withQueryParams([ 'response_type' => 'code', 'client_id' => 'foo', ]); @@ -351,7 +396,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', @@ -377,7 +422,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', @@ -410,7 +455,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, @@ -590,21 +635,31 @@ public function testRespondToAccessTokenRequest(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $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) - ), - ]); + $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) + ), + ] + ); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -650,20 +705,30 @@ public function testRespondToAccessTokenRequestWithDefaultRedirectUri(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $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) - ), - ]); + $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) + ), + ] + ); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -701,9 +766,18 @@ public function testRespondToAccessTokenRequestUsingHttpBasicAuth(): void $authCodeGrant->setEncryptionKey($this->cryptStub->getKey()); $authCodeGrant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $request = (new ServerRequest('', '')) - ->withHeader('Authorization', 'Basic Zm9vOmJhcg==') - ->withParsedBody([ + $request = new ServerRequest( + [], + [], + null, + 'POST', + 'php://input', + [ + 'Authorization' => 'Basic Zm9vOmJhcg==', + ], + [], + [], + [ 'grant_type' => 'authorization_code', 'redirect_uri' => self::REDIRECT_URI, 'code' => $this->cryptStub->doEncrypt( @@ -716,7 +790,8 @@ 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')); @@ -757,21 +832,31 @@ public function testRespondToAccessTokenRequestForPublicClient(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $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) - ), - ]); + $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) + ), + ] + ); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -812,21 +897,31 @@ public function testRespondToAccessTokenRequestNullRefreshToken(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $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) - ), - ]); + $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) + ), + ] + ); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -873,24 +968,34 @@ public function testRespondToAccessTokenRequestCodeChallengePlain(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $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) - ), - ]); + $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) + ), + ] + ); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -937,24 +1042,34 @@ public function testRespondToAccessTokenRequestCodeChallengeS256(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $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) - ), - ]); + $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) + ), + ] + ); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -998,25 +1113,35 @@ public function testPKCEDowngradeBlocked(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $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 - ) - ), - ]); + $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 + ) + ), + ] + ); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -1046,18 +1171,28 @@ public function testRespondToAccessTokenRequestMissingRedirectUri(): void $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -1086,19 +1221,29 @@ public function testRespondToAccessTokenRequestRedirectUriMismatch(): void $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -1127,19 +1272,29 @@ public function testRejectAccessTokenRequestIfRedirectUriSpecifiedButNotInOrigin $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -1172,12 +1327,22 @@ public function testRespondToAccessTokenRequestMissingCode(): void $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = (new ServerRequest('', ''))->withParsedBody([ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'client_secret' => 'bar', - 'redirect_uri' => self::REDIRECT_URI, - ]); + $request = new ServerRequest( + [], + [], + null, + 'POST', + 'php://input', + [], + [], + [], + [ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'client_secret' => 'bar', + 'redirect_uri' => self::REDIRECT_URI, + ] + ); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(3); @@ -1203,21 +1368,31 @@ public function testRespondToAccessTokenRequestWithRefreshTokenInsteadOfAuthCode $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); try { /* @var StubResponseType $response */ @@ -1244,12 +1419,22 @@ public function testRespondToAccessTokenRequestWithAuthCodeNotAString(): void $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = (new ServerRequest('', ''))->withQueryParams([ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => ['not', 'a', 'string'], - ]); + $request = new ServerRequest( + [], + [], + null, + 'POST', + 'php://input', + [], + [], + [], + [ + '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')); @@ -1272,21 +1457,31 @@ public function testRespondToAccessTokenRequestExpiredCode(): void $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); try { /* @var StubResponseType $response */ @@ -1328,21 +1523,31 @@ public function testRespondToAccessTokenRequestRevokedCode(): void $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); try { /* @var StubResponseType $response */ @@ -1382,21 +1587,31 @@ public function testRespondToAccessTokenRequestClientMismatch(): void $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); try { /* @var StubResponseType $response */ @@ -1435,12 +1650,22 @@ public function testRespondToAccessTokenRequestBadCodeEncryption(): void $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $request = (new ServerRequest('', ''))->withParsedBody([ - 'grant_type' => 'authorization_code', - 'client_id' => 'foo', - 'redirect_uri' => self::REDIRECT_URI, - 'code' => 'sdfsfsd', - ]); + $request = new ServerRequest( + [], + [], + null, + 'POST', + 'php://input', + [], + [], + [], + [ + 'grant_type' => 'authorization_code', + 'client_id' => 'foo', + 'redirect_uri' => self::REDIRECT_URI, + 'code' => 'sdfsfsd', + ] + ); try { /* @var StubResponseType $response */ @@ -1488,24 +1713,34 @@ public function testRespondToAccessTokenRequestBadCodeVerifierPlain(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); try { /* @var StubResponseType $response */ @@ -1553,24 +1788,34 @@ public function testRespondToAccessTokenRequestBadCodeVerifierS256(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); try { /* @var StubResponseType $response */ @@ -1618,24 +1863,34 @@ public function testRespondToAccessTokenRequestMalformedCodeVerifierS256WithInva $grant->setScopeRepository($scopeRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); try { /* @var StubResponseType $response */ @@ -1683,24 +1938,34 @@ public function testRespondToAccessTokenRequestMalformedCodeVerifierS256WithInva $grant->setScopeRepository($scopeRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); try { /* @var StubResponseType $response */ @@ -1748,23 +2013,33 @@ public function testRespondToAccessTokenRequestMissingCodeVerifier(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); - $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) - ), - ]); + $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) + ), + ] + ); try { /* @var StubResponseType $response */ @@ -1912,21 +2187,31 @@ public function testRefreshTokenRepositoryUniqueConstraintCheck(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $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) - ), - ]); + $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) + ), + ] + ); /** @var StubResponseType $response */ $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); @@ -1967,21 +2252,31 @@ public function testRefreshTokenRepositoryFailToPersist(): void $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $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) - ), - ]); + $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) + ), + ] + ); $this->expectException(OAuthServerException::class); $this->expectExceptionCode(7); @@ -2025,21 +2320,31 @@ public function testRefreshTokenRepositoryFailToPersistUniqueNoInfiniteLoop(): v $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $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) - ), - ]); + $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) + ), + ] + ); $this->expectException(UniqueTokenIdentifierConstraintViolationException::class); $this->expectExceptionCode(100); @@ -2085,7 +2390,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, @@ -2119,11 +2424,20 @@ public function testUseValidRedirectUriIfScopeCheckFails(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest('', ''))->withQueryParams([ - 'response_type' => 'code', - 'client_id' => 'foo', - 'redirect_uri' => 'http://bar/foo', - ]); + $request = new ServerRequest( + [], + [], + null, + null, + 'php://input', + [], + [], + [ + '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 b401db1ab..69f756c37 100644 --- a/tests/Grant/ClientCredentialsGrantTest.php +++ b/tests/Grant/ClientCredentialsGrantTest.php @@ -5,6 +5,7 @@ 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; @@ -14,7 +15,6 @@ 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 d9c902274..396ea760f 100644 --- a/tests/Grant/DeviceCodeGrantTest.php +++ b/tests/Grant/DeviceCodeGrantTest.php @@ -6,6 +6,8 @@ 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; @@ -23,8 +25,6 @@ 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 34ab01bfe..617aaa842 100644 --- a/tests/Grant/ImplicitGrantTest.php +++ b/tests/Grant/ImplicitGrantTest.php @@ -5,6 +5,7 @@ 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; @@ -22,7 +23,6 @@ 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' => 'token', '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' => 'token', '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' => 'token']); + $request = (new ServerRequest())->withQueryParams(['response_type' => 'token']); $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' => 'token', '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' => 'token', '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' => 'token', 'client_id' => 'foo', 'redirect_uri' => 'http://bar', @@ -223,7 +223,7 @@ public function testValidateAuthorizationRequestInvalidScopes(): void $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); - $request = (new ServerRequest('', ''))->withQueryParams([ + $request = (new ServerRequest())->withQueryParams([ 'response_type' => 'token', 'client_id' => 'foo', 'redirect_uri' => self::REDIRECT_URI, diff --git a/tests/Grant/PasswordGrantTest.php b/tests/Grant/PasswordGrantTest.php index 067721ef6..8c60a8c78 100644 --- a/tests/Grant/PasswordGrantTest.php +++ b/tests/Grant/PasswordGrantTest.php @@ -5,6 +5,7 @@ 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,7 +21,6 @@ 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 5ccd5c5fb..b37001a80 100644 --- a/tests/Grant/RefreshTokenGrantTest.php +++ b/tests/Grant/RefreshTokenGrantTest.php @@ -5,6 +5,7 @@ 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; @@ -19,7 +20,6 @@ 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 d3bedef5f..814e96a6c 100644 --- a/tests/Middleware/AuthorizationServerMiddlewareTest.php +++ b/tests/Middleware/AuthorizationServerMiddlewareTest.php @@ -5,6 +5,8 @@ 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; @@ -16,8 +18,6 @@ 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()); - $request = (new ServerRequest('', ''))->withParsedBody([ - 'grant_type' => 'client_credentials', - 'client_id' => 'foo', - 'client_secret' => 'bar', - ]); + $_POST['grant_type'] = 'client_credentials'; + $_POST['client_id'] = 'foo'; + $_POST['client_secret'] = 'bar'; + + $request = ServerRequestFactory::fromGlobals(); $middleware = new AuthorizationServerMiddleware($server); $response = $middleware->__invoke( @@ -91,11 +91,11 @@ public function testOAuthErrorResponse(): void $server->enableGrantType(new ClientCredentialsGrant(), new DateInterval('PT1M')); - $request = (new ServerRequest('', ''))->withParsedBody([ - 'grant_type' => 'client_credentials', - 'client_id' => 'foo', - 'client_secret' => 'bar', - ]); + $_POST['grant_type'] = 'client_credentials'; + $_POST['client_id'] = 'foo'; + $_POST['client_secret'] = 'bar'; + + $request = ServerRequestFactory::fromGlobals(); $middleware = new AuthorizationServerMiddleware($server); diff --git a/tests/Middleware/ResourceServerMiddlewareTest.php b/tests/Middleware/ResourceServerMiddlewareTest.php index 8edf54670..4a6d3b79e 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 8954a7af2..41ac2e854 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(new ServerRequest('', '')); + $server->validateAuthenticatedRequest(ServerRequestFactory::fromGlobals()); } catch (OAuthServerException $e) { self::assertEquals('Missing "Authorization" header', $e->getHint()); } diff --git a/tests/ResponseTypes/BearerResponseTypeTest.php b/tests/ResponseTypes/BearerResponseTypeTest.php index 05911a6c8..386fb628b 100644 --- a/tests/ResponseTypes/BearerResponseTypeTest.php +++ b/tests/ResponseTypes/BearerResponseTypeTest.php @@ -6,6 +6,8 @@ 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; @@ -15,8 +17,6 @@ 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 a8db43a8b..93bd9d6b3 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 dcbab5043..02f6f14e8 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; From 000ce9a693cf616aab80bf3525a04a2cc5ebbe2a Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Tue, 15 Oct 2024 02:41:32 +0330 Subject: [PATCH 8/8] fix tests --- tests/Grant/RefreshTokenGrantTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Grant/RefreshTokenGrantTest.php b/tests/Grant/RefreshTokenGrantTest.php index 4aa06da05..027731527 100644 --- a/tests/Grant/RefreshTokenGrantTest.php +++ b/tests/Grant/RefreshTokenGrantTest.php @@ -594,10 +594,10 @@ public function testRespondToRequestFinalizeScopes(): void ); $serverRequest = (new ServerRequest())->withParsedBody([ - 'client_id' => 'foo', - 'client_secret' => 'bar', - 'refresh_token' => $encryptedOldRefreshToken, - 'scope' => 'foo bar', + 'client_id' => 'foo', + 'client_secret' => 'bar', + 'refresh_token' => $encryptedOldRefreshToken, + 'scope' => 'foo bar', ]); $responseType = new StubResponseType(); @@ -694,7 +694,7 @@ public function testUnrevokedRefreshToken(): void $accessTokenEntity->setClient($client); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); - $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); + $accessTokenRepositoryMock->method('getNewToken')->willReturn($accessTokenEntity); $accessTokenRepositoryMock->expects(self::once())->method('persistNewAccessToken')->willReturnSelf(); $refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock();