Skip to content

Commit badfde5

Browse files
committed
Rename GooglePublicKey to OpenIdVerificator and rename some methods
1 parent 750c1f6 commit badfde5

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/GooglePublicKey.php renamed to src/OpenIdVerificator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use phpseclib\Crypt\RSA;
1010
use phpseclib\Math\BigInteger;
1111

12-
class GooglePublicKey
12+
class OpenIdVerificator
1313
{
1414
private const V3_CERTS = 'GOOGLE_V3_CERTS';
1515
private const URL_OPENID_CONFIG = 'https://accounts.google.com/.well-known/openid-configuration';
@@ -24,7 +24,7 @@ public function __construct(Client $guzzle, RSA $rsa)
2424
$this->rsa = $rsa;
2525
}
2626

27-
public function get($kid = null)
27+
public function getPublicKey($kid = null)
2828
{
2929
$v3Certs = Cache::rememberForever(self::V3_CERTS, function () {
3030
return $this->getv3Certs();
@@ -52,7 +52,7 @@ private function extractPublicKeyFromCertificate($certificate)
5252
return $this->rsa->getPublicKey();
5353
}
5454

55-
public function getKid($openIdToken)
55+
public function getKidFromOpenIdToken($openIdToken)
5656
{
5757
return $this->callApiAndReturnValue(self::URL_TOKEN_INFO . '?id_token=' . $openIdToken, 'kid');
5858
}

src/TaskHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TaskHandler
1515
private $jwt;
1616
private $publicKey;
1717

18-
public function __construct(CloudTasksClient $client, Request $request, JWT $jwt, GooglePublicKey $publicKey)
18+
public function __construct(CloudTasksClient $client, Request $request, JWT $jwt, OpenIdVerificator $publicKey)
1919
{
2020
$this->client = $client;
2121
$this->request = $request;
@@ -46,8 +46,8 @@ public function authorizeRequest()
4646
}
4747

4848
$openIdToken = $this->request->bearerToken();
49-
$kid = $this->publicKey->getKid($openIdToken);
50-
$publicKey = $this->publicKey->get($kid);
49+
$kid = $this->publicKey->getKidFromOpenIdToken($openIdToken);
50+
$publicKey = $this->publicKey->getPublicKey($kid);
5151

5252
$decodedToken = $this->jwt->decode($openIdToken, $publicKey, ['RS256']);
5353

tests/GooglePublicKeyTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
use Illuminate\Support\Facades\Cache;
77
use Mockery;
88
use phpseclib\Crypt\RSA;
9-
use Stackkit\LaravelGoogleCloudTasksQueue\GooglePublicKey;
9+
use Stackkit\LaravelGoogleCloudTasksQueue\OpenIdVerificator;
1010

1111
class GooglePublicKeyTest extends TestCase
1212
{
1313
/**
14-
* @var GooglePublicKey
14+
* @var OpenIdVerificator
1515
*/
1616
private $publicKey;
1717

@@ -26,31 +26,31 @@ protected function setUp(): void
2626

2727
$this->guzzle = Mockery::mock(new Client());
2828

29-
$this->publicKey = new GooglePublicKey($this->guzzle, new RSA());
29+
$this->publicKey = new OpenIdVerificator($this->guzzle, new RSA());
3030
}
3131

3232
/** @test */
3333
public function it_fetches_the_gcloud_public_key()
3434
{
35-
$this->assertStringContainsString('-----BEGIN PUBLIC KEY-----', $this->publicKey->get());
35+
$this->assertStringContainsString('-----BEGIN PUBLIC KEY-----', $this->publicKey->getPublicKey());
3636
}
3737

3838
/** @test */
3939
public function it_caches_the_gcloud_public_key()
4040
{
4141
$this->assertFalse($this->publicKey->isCached());
4242

43-
$this->publicKey->get();
43+
$this->publicKey->getPublicKey();
4444

4545
$this->assertTrue($this->publicKey->isCached());
4646
}
4747

4848
/** @test */
4949
public function it_will_return_the_cached_gcloud_public_key()
5050
{
51-
$this->publicKey->get();
51+
$this->publicKey->getPublicKey();
5252

53-
$this->publicKey->get();
53+
$this->publicKey->getPublicKey();
5454

5555
$this->guzzle->shouldHaveReceived('get')->twice();
5656
}

tests/TaskHandlerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Mockery;
1111
use phpseclib\Crypt\RSA;
1212
use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksException;
13-
use Stackkit\LaravelGoogleCloudTasksQueue\GooglePublicKey;
13+
use Stackkit\LaravelGoogleCloudTasksQueue\OpenIdVerificator;
1414
use Stackkit\LaravelGoogleCloudTasksQueue\TaskHandler;
1515
use Tests\Support\TestMailable;
1616

@@ -40,9 +40,9 @@ protected function setUp(): void
4040
])->byDefault();
4141

4242
// Ensure we don't fetch the Google public key each test...
43-
$googlePublicKey = Mockery::mock(app(GooglePublicKey::class));
44-
$googlePublicKey->shouldReceive('get')->andReturnNull();
45-
$googlePublicKey->shouldReceive('getKid')->andReturnNull();
43+
$googlePublicKey = Mockery::mock(app(OpenIdVerificator::class));
44+
$googlePublicKey->shouldReceive('getPublicKey')->andReturnNull();
45+
$googlePublicKey->shouldReceive('getKidFromOpenIdToken')->andReturnNull();
4646

4747
$this->handler = new TaskHandler(
4848
new CloudTasksClient([

0 commit comments

Comments
 (0)