Skip to content

Commit

Permalink
Separate chain calls (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
sankaest authored Jun 17, 2022
1 parent 4a075e8 commit 627b111
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/JwtMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public function authenticate(ServerRequestInterface $request): ?IdentityInterfac
return null;
}

$this->getClaimCheckerManager()->check($claims);
$this
->getClaimCheckerManager()
->check($claims);
return $this->identityRepository->findIdentity((string)$claims[$this->identifier]);
}

Expand Down
4 changes: 3 additions & 1 deletion src/TokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function __construct(
public function create(array $payload, string $format, ?int $signatureIndex = null): string
{
$jwsBuilder = new JWSBuilder($this->algorithmManager);
$jws = $jwsBuilder->create()->withPayload(Json::encode($payload));
$jws = $jwsBuilder
->create()
->withPayload(Json::encode($payload));
$jwk = $this->keyFactory->create();

foreach ($this->algorithmManager->list() as $algorithm) {
Expand Down
16 changes: 12 additions & 4 deletions tests/JwtMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function testSuccessfulQueryParameterAuthentication(): void
$payload = $this->getPayload();
$token = $tokenFactory->create($payload, CompactSerializer::NAME);
$result = (new JwtMethod($identityRepository, $this->getTokenRepository()))->authenticate(
$this->createRequest()->withQueryParams(['access-token' => $token])
$this
->createRequest()
->withQueryParams(['access-token' => $token])
);

$this->assertNotNull($result);
Expand All @@ -71,7 +73,9 @@ public function testEmptyPayload(): void
$tokenManager = $this->getTokenFactory();
$token = $tokenManager->create([], CompactSerializer::NAME);
$result = (new JwtMethod($identityRepository, $this->getTokenRepository()))->authenticate(
$this->createRequest()->withQueryParams(['access-token' => $token])
$this
->createRequest()
->withQueryParams(['access-token' => $token])
);

$this->assertNull($result);
Expand All @@ -83,8 +87,12 @@ public function testChallengeIsCorrect(): void
$identityRepository = new FakeIdentityRepository($this->createIdentity());
$authenticationMethod = new JwtMethod($identityRepository, $this->getTokenRepository());

$this->assertEquals(400, $authenticationMethod->challenge($response)->getStatusCode());
$this->assertNotEmpty($authenticationMethod->challenge($response)->getHeaderLine(Header::WWW_AUTHENTICATE));
$this->assertEquals(400, $authenticationMethod
->challenge($response)
->getStatusCode());
$this->assertNotEmpty($authenticationMethod
->challenge($response)
->getHeaderLine(Header::WWW_AUTHENTICATE));
}

public function testCheckTokenIsExpired(): void
Expand Down

0 comments on commit 627b111

Please # to comment.