Skip to content

Commit

Permalink
Merge pull request #77 from google/add-set-subject-on-service-account…
Browse files Browse the repository at this point in the history
…-credentials

allows the setting of subjects on the service account after the fact
  • Loading branch information
stanley-cheung committed Oct 23, 2015
2 parents 5dc5bcb + 0aeae69 commit eed7a67
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ServiceAccountCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,13 @@ public function updateMetadata($metadata,
$jwtCreds = new ServiceAccountJwtAccessCredentials($credJson);
return $jwtCreds->updateMetadata($metadata, $authUri, $client);
}

/**
* @param string sub an email address account to impersonate, in situations when
* the service account has been delegated domain wide access.
*/
public function setSub($sub)
{
$this->auth->setSub($sub);
}
}
18 changes: 18 additions & 0 deletions tests/ServiceAccountCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ public function testShouldBeTheSameAsOAuth2WithTheSameScopeWithSub()
$sa->getCacheKey()
);
}

public function testShouldBeTheSameAsOAuth2WithTheSameScopeWithSubAddedLater()
{
$testJson = createTestJson();
$scope = ['scope/1', 'scope/2'];
$sub = 'sub123';
$sa = new ServiceAccountCredentials(
$scope,
$testJson,
null);
$sa->setSub($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 eed7a67

Please sign in to comment.