Skip to content

Commit

Permalink
feat: private key getters on service account credentials (google-wall…
Browse files Browse the repository at this point in the history
…et#112) (#557)
  • Loading branch information
razvanphp authored Jul 10, 2024
1 parent 1043ea1 commit d2fa07b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Credentials/ServiceAccountCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
12 changes: 12 additions & 0 deletions src/Credentials/ServiceAccountJwtAccessCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
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
8 changes: 8 additions & 0 deletions tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d2fa07b

Please sign in to comment.