Skip to content

Commit

Permalink
token is no longer added to InvalidToken after expired, small changes…
Browse files Browse the repository at this point in the history
… due to scruntinizer
  • Loading branch information
mrcotrmpr committed Sep 21, 2021
1 parent c9d2e01 commit 9eb9588
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
1 change: 0 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function getConfigTreeBuilder(): TreeBuilder
$rootNode = $treeBuilder->getRootNode();

$rootNode
->addDefaultsIfNotSet()
->children()
->booleanNode('is_remembered')
->defaultFalse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token)

if ($this->rememberDeviceResolver->getRememberDeviceStatus()) {
if (is_null($request->cookies) || is_null($request->cookies->get('REMEMBER_DEVICE')) || $this->jwtEncoder->decode($request->cookies->get('REMEMBER_DEVICE'))['exp'] < time()) {
// Only add the token to the invalid tokens table if the expiry time is invalid, not if the cookie is null
if (!is_null($request->cookies) && !is_null($request->cookies->get('REMEMBER_DEVICE'))) {
$this->addToInvalidTokens($request->cookies->get('REMEMBER_DEVICE'));
}

$expiry_time = time() + $this->rememberDeviceResolver->getRememberDeviceExpiryDays() * 86400;
$username = $request->request->get('username');
Expand All @@ -81,7 +77,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token)

$this->addToValidTokens($data, $username);

$response->headers->setCookie(new Cookie('REMEMBER_DEVICE', $data, $expiry_time, '/', null, true, false, $this->sameSite));
$response->headers->setCookie(new Cookie('REMEMBER_DEVICE', $data, $expiry_time, '/', null, true, true, false, $this->sameSite));
}
}

Expand All @@ -96,20 +92,6 @@ public function addResponsePayload(string $key, $value): void
$this->responsePayload[$key] = $value;
}

private function addToInvalidTokens($token): void
{
$entityManager = $this->doctrine->getManager();

$invalidToken = new InvalidToken();
$invalidToken->setToken($token);
$invalidToken->setInvalidatedAt(new \DateTime('now'));

if (!is_null($entityManager)) {
$entityManager->persist($invalidToken);
$entityManager->flush();
}
}

private function addToValidTokens($token, $user): void
{
$entityManager = $this->doctrine->getManager();
Expand Down

0 comments on commit 9eb9588

Please sign in to comment.