diff --git a/src/Credentials/ServiceAccountCredentials.php b/src/Credentials/ServiceAccountCredentials.php index 4090b8931..5e7915333 100644 --- a/src/Credentials/ServiceAccountCredentials.php +++ b/src/Credentials/ServiceAccountCredentials.php @@ -343,6 +343,18 @@ 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. + * + * @return string + */ + public function getPrivateKey() + { + return $this->auth->getSigningKey(); + } + /** * Get the quota project used for this API request * diff --git a/src/Credentials/ServiceAccountJwtAccessCredentials.php b/src/Credentials/ServiceAccountJwtAccessCredentials.php index 6c582a830..7bdc21848 100644 --- a/src/Credentials/ServiceAccountJwtAccessCredentials.php +++ b/src/Credentials/ServiceAccountJwtAccessCredentials.php @@ -217,6 +217,18 @@ 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. + * + * @return string + */ + public function getPrivateKey() + { + 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 818f543ef..4352af154 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(); diff --git a/tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php b/tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php index 2cac3dac1..47e2796ce 100644 --- a/tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php +++ b/tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php @@ -492,6 +492,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();