Skip to content

Commit

Permalink
Merge pull request #20 from gerardnll/patch-1
Browse files Browse the repository at this point in the history
Add nonce attribute in JWT Payload
  • Loading branch information
hywak committed Oct 29, 2021
2 parents d31554c + b099cbb commit 5f09053
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Auth/Factory/AppleJwtStructFactory.php
Expand Up @@ -28,7 +28,8 @@ public function createJwtPayloadFromToken(Token $token): JwtPayload
// For some reason Apple API returns boolean flag as a string
(string) $claims->get('is_private_email', 'false') === 'true',
$claims->get('auth_time'),
$claims->get('nonce_supported', false)
$claims->get('nonce_supported', false),
$claims->get('nonce')
);
}
}
11 changes: 10 additions & 1 deletion src/Auth/Struct/JwtPayload.php
Expand Up @@ -26,6 +26,8 @@ final class JwtPayload

private int $authTime;

private ?string $nonce;

private bool $nonceSupported;

public function __construct(
Expand All @@ -39,7 +41,8 @@ public function __construct(
bool $emailVerified,
bool $isPrivateEmail,
int $authTime,
bool $nonceSupported
bool $nonceSupported,
?string $nonce
) {
$this->iss = $iss;
$this->aud = $aud;
Expand All @@ -52,6 +55,7 @@ public function __construct(
$this->isPrivateEmail = $isPrivateEmail;
$this->authTime = $authTime;
$this->nonceSupported = $nonceSupported;
$this->nonce = $nonce;
}

public function getIss(): string
Expand Down Expand Up @@ -104,6 +108,11 @@ public function getAuthTime(): int
return $this->authTime;
}

public function getNonce(): ?string
{
return $this->nonce;
}

public function isNonceSupported(): bool
{
return $this->nonceSupported;
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Auth/Factory/AppleJwtStructFactoryTest.php
Expand Up @@ -35,7 +35,8 @@ public function testIfCreateJwtPayloadFromTokenReturnsExpectedJsonPayload(): voi
true,
true,
1591622011,
true
true,
null
),
$this->appleJwtStructFactory->createJwtPayloadFromToken(
new Token\Plain(
Expand All @@ -57,7 +58,7 @@ public function testIfCreateJwtPayloadFromTokenReturnsExpectedJsonPayload(): voi
'email_verified' => 'true',
'is_private_email' => 'true',
'auth_time' => 1591622011,
'nonce_supported' => true,
'nonce_supported' => true
], ''
),
Token\Signature::fromEmptyData()
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Auth/Service/AppleJwtFetchingServiceTest.php
Expand Up @@ -115,7 +115,8 @@ public function testIfGetJwtPayloadReturnsExpectedJwtPayloadWhenTokenIsVerifiedA
true,
true,
1591622011,
true
true,
null
);

$this->factoryMock->shouldReceive('createJwtPayloadFromToken')
Expand Down

0 comments on commit 5f09053

Please sign in to comment.