Skip to content

Commit

Permalink
WIP for handling file cert locations
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Jul 9, 2024
1 parent d001a7f commit a6527ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 19 additions & 2 deletions src/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Google\Auth\HttpHandler\HttpHandlerFactory;
use GuzzleHttp\Psr7\HttpFactory;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;
use InvalidArgumentException;
use Psr\Cache\CacheItemPoolInterface;
Expand Down Expand Up @@ -118,10 +119,26 @@ public function verify($token, array $options = [])
$certsLocation = $options['certsLocation'] ?? self::FEDERATED_SIGNON_CERT_URL;
$throwException = $options['throwException'] ?? false; // for backwards compatibility

// Check signature against each available cert.
// If we're retrieving a local file, just grab it.
$httpHandler = null;
if (strpos($certsLocation, 'http') !== 0) {
if (!file_exists($certsLocation)) {
throw new InvalidArgumentException(sprintf(
'Failed to retrieve verification certificates from path: %s.',
$certsLocation
));
}

$httpHandler = function () use ($certsLocation) {
return new Response(200, [
'cache-control' => 'public, max-age=1000',
], file_get_contents($certsLocation));

Check failure on line 135 in src/AccessToken.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis

Parameter #3 $body of class GuzzleHttp\Psr7\Response constructor expects Psr\Http\Message\StreamInterface|resource|string|null, string|false given.
};
}

$keySet = new CachedKeySet(
$certsLocation,
new class($this->httpHandler) implements ClientInterface {
new class($httpHandler ?: $this->httpHandler) implements ClientInterface {
public function __construct(private $httpHandler)

Check failure on line 142 in src/AccessToken.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis

Method class@anonymous/AccessToken.php:141::__construct() has parameter $httpHandler with no type specified.
{
}
Expand Down
6 changes: 1 addition & 5 deletions tests/AccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,7 @@ public function testRetrieveCertsFromLocationLocalFile()
});

$token = new AccessToken(
function ($request) {
return new Response(200, [
'cache-control' => 'public, max-age=1000',
], file_get_contents((string)$request->getUri()));
},
null,
$this->cache->reveal(),
$jwt
);
Expand Down

0 comments on commit a6527ef

Please sign in to comment.