Skip to content

Commit

Permalink
Encode "aud" as string when we just have one permitted client
Browse files Browse the repository at this point in the history
  • Loading branch information
lcobucci committed Feb 17, 2017
1 parent d57ac6a commit 31a7d7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Token/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public function getToken(Signer $signer, Key $key): Plain

private function formatClaims(array $claims): array
{
if (isset($claims[RegisteredClaims::AUDIENCE]) && count($claims[RegisteredClaims::AUDIENCE]) === 1) {
$claims[RegisteredClaims::AUDIENCE] = $claims[RegisteredClaims::AUDIENCE][0];
}

foreach (RegisteredClaims::DATE_CLAIMS as $claim) {
if (!isset($claims[$claim])) {
continue;
Expand Down
3 changes: 2 additions & 1 deletion test/unit/Token/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public function getTokenMustReturnANewTokenWithCurrentConfiguration(): void
$this->signer->method('sign')->willReturn('testing');

$headers = ['typ' => 'JWT', 'alg' => 'RS256'];
$claims = ['test' => 123, 'iat' => 1487285080, 'exp' => '1487285080.123456'];
$claims = ['test' => 123, 'aud' => 'test', 'iat' => 1487285080, 'exp' => '1487285080.123456'];

$this->encoder->expects($this->exactly(2))
->method('jsonEncode')
Expand All @@ -429,6 +429,7 @@ public function getTokenMustReturnANewTokenWithCurrentConfiguration(): void
$token = $this->createBuilder()
->issuedAt(new DateTimeImmutable('@1487285080'))
->expiresAt(DateTimeImmutable::createFromFormat('U.u', '1487285080.123456'))
->permittedFor('test')
->withClaim('test', 123)
->getToken($this->signer, new Key('123'));

Expand Down

0 comments on commit 31a7d7f

Please sign in to comment.