Skip to content

Commit

Permalink
feat: service get account private key for JWT encode (google-walle#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanphp committed Jun 1, 2024
1 parent bff9f2d commit 89416cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Credentials/ServiceAccountCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
7 changes: 7 additions & 0 deletions tests/Credentials/ServiceAccountCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 89416cf

Please sign in to comment.