From be34ee524c7c60ad54097f989925cd4d6b5448bb Mon Sep 17 00:00:00 2001 From: Rick Lambrechts Date: Thu, 8 May 2025 10:25:35 +0200 Subject: [PATCH 1/4] feat: support laravel 12 --- .github/workflows/ci.yml | 8 ++++++-- composer.json | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68fd643..3f2d6ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,8 +13,8 @@ jobs: strategy: fail-fast: false matrix: - php: [ 8.1, 8.2, 8.3 ] - laravel: [ 10.*, 11.* ] + php: [ 8.1, 8.2, 8.3, 8.4 ] + laravel: [ 10.*, 11.*, 12.* ] stability: [ prefer-stable ] experimental: [ false ] include: @@ -22,9 +22,13 @@ jobs: testbench: 8.* - laravel: 11.* testbench: 9.* + - laravel: 12.* + testbench: 10.* exclude: - php: 8.1 laravel: 11.* + - php: 8.1 + laravel: 12.* name: PHP ${{ matrix.php }} - L${{ matrix.laravel }} diff --git a/composer.json b/composer.json index fcea659..6458da5 100644 --- a/composer.json +++ b/composer.json @@ -33,12 +33,12 @@ "php": ">=8.1", "jumbojett/openid-connect-php": "^1.0.2", "guzzlehttp/guzzle": "^7.5", - "illuminate/contracts": "^10.0||^11.0", + "illuminate/contracts": "^10.0||^11.0||^12.0", "web-token/jwt-library": "^3.4" }, "require-dev": { - "orchestra/testbench": "^8.0||^9.0", - "phpunit/phpunit": "^10.0", + "orchestra/testbench": "^8.0||^9.0||^10.0", + "phpunit/phpunit": "^10.0||^11.0||^12.0", "vimeo/psalm": "^5.8", "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.8", From b86ea3d2c1a35b52384f6aae31ffa21117a41625 Mon Sep 17 00:00:00 2001 From: Rick Lambrechts Date: Mon, 12 May 2025 13:40:54 +0200 Subject: [PATCH 2/4] Allow psalm 6 --- .github/workflows/ci.yml | 9 ++++----- composer.json | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f2d6ae..5eebafa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,11 +53,10 @@ jobs: composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update --dev --ignore-platform-reqs composer update --${{ matrix.stability }} --prefer-dist --no-interaction --ignore-platform-reqs - - name: Setup problem matchers for PHP - run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" - - - name: Setup problem matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Execute tests (Unit and Feature) run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index 6458da5..b8e0632 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "require-dev": { "orchestra/testbench": "^8.0||^9.0||^10.0", "phpunit/phpunit": "^10.0||^11.0||^12.0", - "vimeo/psalm": "^5.8", + "vimeo/psalm": "^5.8||^6.0", "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.8", "slevomat/coding-standard": "^8.14", From 95ca89e5a169454ef1eb90ec09da0282f5f86469 Mon Sep 17 00:00:00 2001 From: Rick Lambrechts Date: Mon, 12 May 2025 14:17:21 +0200 Subject: [PATCH 3/4] Add override attribute --- src/Http/Responses/LoginResponseHandler.php | 1 + src/OpenIDConnectClient.php | 11 +++++++++++ src/OpenIDConnectServiceProvider.php | 1 + src/Services/ExceptionHandler.php | 3 +++ src/Services/JWE/JweDecryptService.php | 1 + 5 files changed, 17 insertions(+) diff --git a/src/Http/Responses/LoginResponseHandler.php b/src/Http/Responses/LoginResponseHandler.php index 2bedbfa..83a9f90 100644 --- a/src/Http/Responses/LoginResponseHandler.php +++ b/src/Http/Responses/LoginResponseHandler.php @@ -9,6 +9,7 @@ class LoginResponseHandler implements LoginResponseHandlerInterface { + #[\Override] public function handleLoginResponse(object $userInfo): Response { return new JsonResponse([ diff --git a/src/OpenIDConnectClient.php b/src/OpenIDConnectClient.php index 286526b..7ea9e51 100644 --- a/src/OpenIDConnectClient.php +++ b/src/OpenIDConnectClient.php @@ -40,11 +40,13 @@ public function __construct( $this->openIDConfiguration = $openIDConfiguration; } + #[\Override] protected function startSession(): void { // Laravel magic in the background :) } + #[\Override] protected function commitSession(): void { Session::save(); @@ -53,6 +55,7 @@ protected function commitSession(): void /** * @param string $key */ + #[\Override] protected function getSessionKey($key): mixed { if (!Session::has($key)) { @@ -66,6 +69,7 @@ protected function getSessionKey($key): mixed * @param string $key * @param mixed $value mixed */ + #[\Override] protected function setSessionKey($key, $value): void { Session::put($key, $value); @@ -74,6 +78,7 @@ protected function setSessionKey($key, $value): void /** * @param string $key */ + #[\Override] protected function unsetSessionKey($key): void { Session::remove($key); @@ -84,6 +89,7 @@ protected function unsetSessionKey($key): void * @return string the JWT payload * @throws OpenIDConnectClientException */ + #[\Override] protected function handleJweResponse($jwe): string { if ($this->jweDecrypter === null) { @@ -102,6 +108,7 @@ protected function handleJweResponse($jwe): string * @throws OpenIDConnectClientException * @return string|string[]|bool */ + #[\Override] protected function getWellKnownConfigValue($param, $default = null): string|array|bool { if ($this->openIDConfiguration === null) { @@ -137,6 +144,7 @@ public function setLoginHint(?string $loginHint = null): void * @return void * @throws OpenIDConnectClientException */ + #[\Override] public function redirect($url): void { throw new HttpResponseException(new RedirectResponse($url)); @@ -173,6 +181,7 @@ protected function getAuthorizationEndpoint(): string * @throws OpenIDConnectClientException */ protected function fetchURL(string $url, string $post_body = null, array $headers = []): string + #[\Override] { $pendingRequest = Http::withUserAgent($this->getUserAgent()) ->timeout($this->timeOut) @@ -211,6 +220,7 @@ protected function fetchURL(string $url, string $post_body = null, array $header * * @return int */ + #[\Override] public function getResponseCode(): int { return $this->responseCode ?? 0; @@ -221,6 +231,7 @@ public function getResponseCode(): int * * @return string|null */ + #[\Override] public function getResponseContentType(): ?string { return $this->internalResponseContentType; diff --git a/src/OpenIDConnectServiceProvider.php b/src/OpenIDConnectServiceProvider.php index 733682c..14b2b76 100644 --- a/src/OpenIDConnectServiceProvider.php +++ b/src/OpenIDConnectServiceProvider.php @@ -25,6 +25,7 @@ class OpenIDConnectServiceProvider extends ServiceProvider { + #[\Override] public function register(): void { $this->mergeConfigFrom(__DIR__ . '/../config/oidc.php', 'oidc'); diff --git a/src/Services/ExceptionHandler.php b/src/Services/ExceptionHandler.php index 147f747..bf96b64 100644 --- a/src/Services/ExceptionHandler.php +++ b/src/Services/ExceptionHandler.php @@ -17,6 +17,7 @@ public function __construct( ) { } + #[\Override] public function handleExceptionWhileAuthenticate(OpenIDConnectClientException $exception): Response { if (str_starts_with($exception->getMessage(), 'Error: ')) { @@ -38,6 +39,7 @@ public function handleExceptionWhileAuthenticate(OpenIDConnectClientException $e * @param OpenIDConnectClientException $exception * @return Response */ + #[\Override] public function handleExceptionWhileRequestUserInfo(OpenIDConnectClientException $exception): Response { $this->logger?->error('OIDC Exception occurred while requesting user info', [ @@ -47,6 +49,7 @@ public function handleExceptionWhileRequestUserInfo(OpenIDConnectClientException return $this->defaultResponse($exception); } + #[\Override] public function handleException(Exception $exception): Response { $this->logger?->error('OIDC Generic exception occurred', [ diff --git a/src/Services/JWE/JweDecryptService.php b/src/Services/JWE/JweDecryptService.php index cb1fc69..b91b88b 100644 --- a/src/Services/JWE/JweDecryptService.php +++ b/src/Services/JWE/JweDecryptService.php @@ -35,6 +35,7 @@ public function __construct( /** * @throws JweDecryptException */ + #[\Override] public function decrypt(string $jweString): string { $jwe = $this->serializerManager->unserialize($jweString); From 0234a0dcc160e008f19a486c10982d81cdcbea82 Mon Sep 17 00:00:00 2001 From: Rick Lambrechts Date: Mon, 12 May 2025 14:17:35 +0200 Subject: [PATCH 4/4] Fix typing in OpenIDConnectClient --- src/OpenIDConnectClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenIDConnectClient.php b/src/OpenIDConnectClient.php index 7ea9e51..2e79177 100644 --- a/src/OpenIDConnectClient.php +++ b/src/OpenIDConnectClient.php @@ -180,8 +180,8 @@ protected function getAuthorizationEndpoint(): string * @return string * @throws OpenIDConnectClientException */ - protected function fetchURL(string $url, string $post_body = null, array $headers = []): string #[\Override] + protected function fetchURL(string $url, ?string $post_body = null, array $headers = []): string { $pendingRequest = Http::withUserAgent($this->getUserAgent()) ->timeout($this->timeOut)