Skip to content

Commit

Permalink
Ensure that tests work with credential files and arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Jan 2, 2024
1 parent cd7062c commit 25fa794
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 25fa794

Please sign in to comment.