From 5ebf5bc27ecb4120e6cca46c4c87d07a3b8862ba Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Sat, 1 Jun 2024 18:28:57 +0300 Subject: [PATCH 1/3] feat: service get account private key for JWT encode (google-wallet#112) --- .../ServiceAccountJwtAccessCredentials.php | 13 +++++++++++++ .../ServiceAccountJwtAccessCredentialsTest.php | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Credentials/ServiceAccountJwtAccessCredentials.php b/src/Credentials/ServiceAccountJwtAccessCredentials.php index 87baa7500..e20198c08 100644 --- a/src/Credentials/ServiceAccountJwtAccessCredentials.php +++ b/src/Credentials/ServiceAccountJwtAccessCredentials.php @@ -207,6 +207,19 @@ public function getClientName(callable $httpHandler = null) return $this->auth->getIssuer(); } + /** + * Get the private key from the keyfile. + * + * In this case, it returns the keyfile's private_key key, needed for JWT signing. + * + * @param callable $httpHandler Not used by this credentials type. + * @return string + */ + public function getPrivateKey(callable $httpHandler = null) + { + return $this->auth->getSigningKey(); + } + /** * Get the quota project used for this API request * diff --git a/tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php b/tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php index 510225dd7..d274e6f0f 100644 --- a/tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php +++ b/tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php @@ -490,6 +490,14 @@ public function testReturnsClientEmail() $sa = new ServiceAccountJwtAccessCredentials($testJson); $this->assertEquals($testJson['client_email'], $sa->getClientName()); } + + public function testReturnsPrivateKey() + { + $testJson = $this->createTestJson(); + $sa = new ServiceAccountJwtAccessCredentials($testJson); + $this->assertEquals($testJson['private_key'], $sa->getPrivateKey()); + } + public function testGetProjectId() { $testJson = $this->createTestJson(); From 5b32b32b8d7dfa6bccdf3400a9319907dd4729e6 Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Wed, 10 Jul 2024 17:58:56 +0300 Subject: [PATCH 2/3] feat: service get account private key for JWT encode (google-wallet#112) --- src/Credentials/ServiceAccountCredentials.php | 13 +++++++++++++ tests/Credentials/ServiceAccountCredentialsTest.php | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/Credentials/ServiceAccountCredentials.php b/src/Credentials/ServiceAccountCredentials.php index 91238029d..e6976b2a4 100644 --- a/src/Credentials/ServiceAccountCredentials.php +++ b/src/Credentials/ServiceAccountCredentials.php @@ -333,6 +333,19 @@ public function getClientName(callable $httpHandler = null) return $this->auth->getIssuer(); } + /** + * Get the private key from the keyfile. + * + * In this case, it returns the keyfile's private_key key, needed for JWT signing. + * + * @param callable $httpHandler Not used by this credentials type. + * @return string + */ + public function getPrivateKey(callable $httpHandler = null) + { + return $this->auth->getSigningKey(); + } + /** * Get the quota project used for this API request * diff --git a/tests/Credentials/ServiceAccountCredentialsTest.php b/tests/Credentials/ServiceAccountCredentialsTest.php index a53f55158..d065e0264 100644 --- a/tests/Credentials/ServiceAccountCredentialsTest.php +++ b/tests/Credentials/ServiceAccountCredentialsTest.php @@ -369,6 +369,13 @@ public function testReturnsClientEmail() $this->assertEquals($testJson['client_email'], $sa->getClientName()); } + public function testReturnsPrivateKey() + { + $testJson = $this->createTestJson(); + $sa = new ServiceAccountCredentials('scope/1', $testJson); + $this->assertEquals($testJson['private_key'], $sa->getPrivateKey()); + } + public function testGetProjectId() { $testJson = $this->createTestJson(); From b90a9637ddbf8f8d44619acb53c7281a3b9a713d Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Wed, 10 Jul 2024 19:30:53 +0300 Subject: [PATCH 3/3] feat: service get account private key does not need $httpHandler (google-wallet#112) --- src/Credentials/ServiceAccountCredentials.php | 3 +-- src/Credentials/ServiceAccountJwtAccessCredentials.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Credentials/ServiceAccountCredentials.php b/src/Credentials/ServiceAccountCredentials.php index e6976b2a4..4a4422adf 100644 --- a/src/Credentials/ServiceAccountCredentials.php +++ b/src/Credentials/ServiceAccountCredentials.php @@ -338,10 +338,9 @@ public function getClientName(callable $httpHandler = null) * * In this case, it returns the keyfile's private_key key, needed for JWT signing. * - * @param callable $httpHandler Not used by this credentials type. * @return string */ - public function getPrivateKey(callable $httpHandler = null) + public function getPrivateKey() { return $this->auth->getSigningKey(); } diff --git a/src/Credentials/ServiceAccountJwtAccessCredentials.php b/src/Credentials/ServiceAccountJwtAccessCredentials.php index e20198c08..33a30b4ee 100644 --- a/src/Credentials/ServiceAccountJwtAccessCredentials.php +++ b/src/Credentials/ServiceAccountJwtAccessCredentials.php @@ -212,10 +212,9 @@ public function getClientName(callable $httpHandler = null) * * In this case, it returns the keyfile's private_key key, needed for JWT signing. * - * @param callable $httpHandler Not used by this credentials type. * @return string */ - public function getPrivateKey(callable $httpHandler = null) + public function getPrivateKey() { return $this->auth->getSigningKey(); }