Skip to content

Commit 5ebf5bc

Browse files
committed
feat: service get account private key for JWT encode (google-wallet#112)
1 parent bff9f2d commit 5ebf5bc

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/Credentials/ServiceAccountJwtAccessCredentials.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ public function getClientName(callable $httpHandler = null)
207207
return $this->auth->getIssuer();
208208
}
209209

210+
/**
211+
* Get the private key from the keyfile.
212+
*
213+
* In this case, it returns the keyfile's private_key key, needed for JWT signing.
214+
*
215+
* @param callable $httpHandler Not used by this credentials type.
216+
* @return string
217+
*/
218+
public function getPrivateKey(callable $httpHandler = null)
219+
{
220+
return $this->auth->getSigningKey();
221+
}
222+
210223
/**
211224
* Get the quota project used for this API request
212225
*

tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,14 @@ public function testReturnsClientEmail()
490490
$sa = new ServiceAccountJwtAccessCredentials($testJson);
491491
$this->assertEquals($testJson['client_email'], $sa->getClientName());
492492
}
493+
494+
public function testReturnsPrivateKey()
495+
{
496+
$testJson = $this->createTestJson();
497+
$sa = new ServiceAccountJwtAccessCredentials($testJson);
498+
$this->assertEquals($testJson['private_key'], $sa->getPrivateKey());
499+
}
500+
493501
public function testGetProjectId()
494502
{
495503
$testJson = $this->createTestJson();

0 commit comments

Comments
 (0)