Skip to content

Commit d2fa07b

Browse files
authored
feat: private key getters on service account credentials (google-wallet#112) (#557)
1 parent 1043ea1 commit d2fa07b

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

src/Credentials/ServiceAccountCredentials.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,18 @@ public function getClientName(callable $httpHandler = null)
343343
return $this->auth->getIssuer();
344344
}
345345

346+
/**
347+
* Get the private key from the keyfile.
348+
*
349+
* In this case, it returns the keyfile's private_key key, needed for JWT signing.
350+
*
351+
* @return string
352+
*/
353+
public function getPrivateKey()
354+
{
355+
return $this->auth->getSigningKey();
356+
}
357+
346358
/**
347359
* Get the quota project used for this API request
348360
*

src/Credentials/ServiceAccountJwtAccessCredentials.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ public function getClientName(callable $httpHandler = null)
217217
return $this->auth->getIssuer();
218218
}
219219

220+
/**
221+
* Get the private key from the keyfile.
222+
*
223+
* In this case, it returns the keyfile's private_key key, needed for JWT signing.
224+
*
225+
* @return string
226+
*/
227+
public function getPrivateKey()
228+
{
229+
return $this->auth->getSigningKey();
230+
}
231+
220232
/**
221233
* Get the quota project used for this API request
222234
*

tests/Credentials/ServiceAccountCredentialsTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,13 @@ public function testReturnsClientEmail()
369369
$this->assertEquals($testJson['client_email'], $sa->getClientName());
370370
}
371371

372+
public function testReturnsPrivateKey()
373+
{
374+
$testJson = $this->createTestJson();
375+
$sa = new ServiceAccountCredentials('scope/1', $testJson);
376+
$this->assertEquals($testJson['private_key'], $sa->getPrivateKey());
377+
}
378+
372379
public function testGetProjectId()
373380
{
374381
$testJson = $this->createTestJson();

tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,14 @@ public function testReturnsClientEmail()
492492
$sa = new ServiceAccountJwtAccessCredentials($testJson);
493493
$this->assertEquals($testJson['client_email'], $sa->getClientName());
494494
}
495+
496+
public function testReturnsPrivateKey()
497+
{
498+
$testJson = $this->createTestJson();
499+
$sa = new ServiceAccountJwtAccessCredentials($testJson);
500+
$this->assertEquals($testJson['private_key'], $sa->getPrivateKey());
501+
}
502+
495503
public function testGetProjectId()
496504
{
497505
$testJson = $this->createTestJson();

0 commit comments

Comments
 (0)