diff --git a/src/ServiceAccountCredentials.php b/src/ServiceAccountCredentials.php index 2e8810e68..e9a52a7e6 100644 --- a/src/ServiceAccountCredentials.php +++ b/src/ServiceAccountCredentials.php @@ -98,6 +98,10 @@ public function __construct($scope, $jsonKey, */ public function getCacheKey() { - return $this->auth->getIssuer() . ':' . $this->auth->getCacheKey(); + $key = $this->auth->getIssuer() . ':' . $this->auth->getCacheKey(); + if ($sub = $this->auth->getSub()) { + $key .= ':' . $sub; + } + return $key; } } diff --git a/tests/ServiceAccountCredentialsTest.php b/tests/ServiceAccountCredentialsTest.php index 398a252aa..0c8ceb0ca 100644 --- a/tests/ServiceAccountCredentialsTest.php +++ b/tests/ServiceAccountCredentialsTest.php @@ -53,6 +53,23 @@ public function testShouldBeTheSameAsOAuth2WithTheSameScope() $sa->getCacheKey() ); } + + public function testShouldBeTheSameAsOAuth2WithTheSameScopeWithSub() + { + $testJson = createTestJson(); + $scope = ['scope/1', 'scope/2']; + $sub = 'sub123'; + $sa = new ServiceAccountCredentials( + $scope, + $testJson, + null, + $sub); + $o = new OAuth2(['scope' => $scope]); + $this->assertSame( + $testJson['client_email'] . ':' . $o->getCacheKey() . ':' . $sub, + $sa->getCacheKey() + ); + } } class SACConstructorTest extends \PHPUnit_Framework_TestCase