From 25fa794a7d9dea07eea3b04f400cc68dd646b847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gamez?= Date: Tue, 2 Jan 2024 14:54:06 +0100 Subject: [PATCH] Ensure that tests work with credential files and arrays --- tests/TestCase.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 3f10cc1..0a77380 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,10 +2,14 @@ namespace Beste\Firebase\JWT\Tests; +use Beste\Cache\InMemoryCache; +use Beste\Clock\SystemClock; use Beste\Firebase\JWT\Environment\EnvironmentVariables; use Beste\Firebase\JWT\Environment\Variables; use Beste\Firebase\JWT\Tests\Support\CustomTokenExchanger; -use Google\Auth\ApplicationDefaultCredentials; +use Google\Auth\Credentials\ServiceAccountCredentials; +use Google\Auth\FetchAuthTokenCache; +use Google\Auth\Middleware\AuthTokenMiddleware; use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; use Http\Discovery\Psr17FactoryDiscovery; @@ -47,7 +51,12 @@ protected static function customTokenExchanger(): CustomTokenExchanger return self::$customTokenExchanger; } - $middleware = ApplicationDefaultCredentials::getMiddleware(['https://www.googleapis.com/auth/cloud-platform']); + $credentials = new ServiceAccountCredentials(['https://www.googleapis.com/auth/cloud-platform'], [ + 'client_email' => self::variables()->clientEmail(), + 'private_key' => self::variables()->privateKey(), + ]); + $credentials = new FetchAuthTokenCache(fetcher: $credentials, cacheConfig: [], cache: new InMemoryCache(SystemClock::create())); + $middleware = new AuthTokenMiddleware($credentials); $stack = HandlerStack::create(); $stack->push($middleware);