Skip to content

Commit

Permalink
fixup! Fix lexik#1137 Invalidate token
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovic Daoudal committed Nov 23, 2023
1 parent 94967fd commit 1c371a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Resources/doc/10-invalidate-token.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Invalidate token
================

The blocklist token relies on the ``jti`` claim, a standard claim designed for tracking and revoking JWTs. `"jti" (JWT ID) Claim <https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7>`_
The token blocklist relies on the ``jti`` claim, a standard claim designed for tracking and revoking JWTs. `"jti" (JWT ID) Claim <https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7>`_

The blocklist storage utilizes a cache implementing ``Psr\Cache\CacheItemPoolInterface``. The cache stores the ``jti`` of the blocked token to the cache, and the cache item expires after the "exp" (expiration time) claim of the token

Expand Down Expand Up @@ -46,7 +46,7 @@ To block JWTs on logout, you must either activate logout in the firewall configu
logout:
path: app_logout
- programmatically in an controller action
* programmatically in a controller action

.. code-block:: php
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand All @@ -58,7 +58,7 @@ To block JWTs on logout, you must either activate logout in the firewall configu
class SecurityController
{
//...
public function logoutAction(Request $request, EventDispatcherInterface $eventDispatcher, TokenStorageInterface $tokenStorage)
public function logout(Request $request, EventDispatcherInterface $eventDispatcher, TokenStorageInterface $tokenStorage)
{
$eventDispatcher->dispatch(new LogoutEvent($request, $tokenStorage->getToken()));
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/BlocklistTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testShouldInvalidateTokenOnLogoutWhenBlockListTokenIsEnabled()
$token = static::getAuthenticatedToken();

static::$client->jsonRequest('GET', '/api/secured', [], ['HTTP_AUTHORIZATION' => "Bearer $token"]);
static::assertResponseIsSuccessful('Pre condition - a valid token should be able to contact the api');
static::assertResponseIsSuccessful('Precondition - a valid token should be able to contact the api');

static::$client->jsonRequest('GET', '/api/logout', [], ['HTTP_AUTHORIZATION' => "Bearer $token"]);
static::assertResponseStatusCodeSame(Response::HTTP_FOUND);
Expand Down Expand Up @@ -48,7 +48,7 @@ public function testShouldInvalidateTokenOnLogoutWhenBlockListTokenIsEnabledAndW
$token = static::getAuthenticatedToken();

static::$client->jsonRequest('GET', '/api/secured', [], ['HTTP_AUTHORIZATION' => "Bearer $token"]);
static::assertResponseIsSuccessful('Pre condition - a valid token should be able to contact the api');
static::assertResponseIsSuccessful('Precondition - a valid token should be able to contact the api');

static::$client->jsonRequest('GET', '/api/logout_custom', [], ['HTTP_AUTHORIZATION' => "Bearer $token"]);
static::assertResponseStatusCodeSame(Response::HTTP_OK);
Expand All @@ -67,7 +67,7 @@ public function testShouldNotInvalidateTokenOnLogoutWhenBlockListTokenIsDisabled
$token = static::getAuthenticatedToken();

static::$client->jsonRequest('GET', '/api/secured', [], ['HTTP_AUTHORIZATION' => "Bearer $token"]);
static::assertResponseIsSuccessful('Pre condition - a valid token should be able to contact the api');
static::assertResponseIsSuccessful('Precondition - a valid token should be able to contact the api');

static::$client->jsonRequest('GET', '/api/logout', [], ['HTTP_AUTHORIZATION' => "Bearer $token"]);
static::assertResponseStatusCodeSame(Response::HTTP_FOUND);
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testShouldInvalidateTokenIfDisabledUserWhenBlockListTokenIsEnabl
/** @var UserProvider $userProvider */
UserProvider::$users['lexik_disabled']['enabled'] = false;
static::$client->jsonRequest('GET', '/api/secured', [], ['HTTP_AUTHORIZATION' => "Bearer $token"]);
static::assertResponseStatusCodeSame(Response::HTTP_UNAUTHORIZED, 'An user disabled should invalidate token');
static::assertResponseStatusCodeSame(Response::HTTP_UNAUTHORIZED, 'An user disabled should be able to contact the api');
$this->assertThatTokenIsInTheBlockList($token);
}

Expand Down

0 comments on commit 1c371a9

Please sign in to comment.