Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: service get account private key for JWT encode #557

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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