Skip to content

Commit

Permalink
Merge pull request #21 from stanley-cheung/include_sub_sac_cachekey
Browse files Browse the repository at this point in the history
Include 'sub' in ServiceAccountCredentials cache key, if available
  • Loading branch information
tbetbetbe committed Apr 21, 2015
2 parents e3a0716 + f089e19 commit dacbef6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ServiceAccountCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
17 changes: 17 additions & 0 deletions tests/ServiceAccountCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dacbef6

Please sign in to comment.