Skip to content

Commit

Permalink
added README, altered username variable type and removed duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcotrmpr committed Sep 22, 2021
1 parent 9eb9588 commit 385641e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,28 @@ If correct you'll receive:

The response headers will include a secure cookie containing the JWT token to allow future authenticated calls.

## 2FA Remember this device

The remember device functionality allows users to skip the 2fa for a configurable amount of days. The default configuration is set to false, which means it doesn't set a REMEMBER_DEVICE cookie after logging in.
The default amount of days is set to 30.

To configure:


In the config/packages folder of the root project create a new file called:
`connect_holland_secure_jwt.yaml`

In this file the configuration can be set:

```yaml
connect_holland_secure_jwt:
is_remembered: true
expiry_days: 14
```

As mentioned before, after logging in a REMEMBER_DEVICE cookie will be set. It will contain a unix expiry time and the email of the user.

Besides placing the cookie it will be persisted in the: `secure_jwt_remember_device_token` table. This entity can be found in `src/Entity/RememberDeviceToken.php`

## Recover codes
You can retrieve recovery codes for 2FA which allow you to reset 2FA. If a valid recovery code is entered as `challenge`, 2FA will be reset and you'll get a QR code response.
2 changes: 1 addition & 1 deletion src/Entity/RememberDeviceToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RememberDeviceToken
private string $token;

/**
* @ORM\Column(type="text")
* @ORM\Column(type="string", length=180)
*/
private string $username;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testOnAuthenticationSuccess(): void
$request = $this->getRequest();
$token = $this->getToken();

$response = (new AuthenticationSuccessHandler(new LexikAuthenticationSuccessHandler($this->getJWTManager('secrettoken'), $this->getDispatcher()), $this->getEncoder(), 'strict', $this->getFalseRememberDeviceResolver(), $this->getDoctrine()))
$response = (new AuthenticationSuccessHandler(new LexikAuthenticationSuccessHandler($this->getJWTManager('secrettoken'), $this->getDispatcher()), $this->getEncoder(), 'strict', $this->getRememberDeviceResolver(false), $this->getDoctrine()))
->onAuthenticationSuccess($request, $token);

$this->assertInstanceOf(JsonResponse::class, $response);
Expand All @@ -52,7 +52,7 @@ public function testOnAuthenticationSuccess(): void

public function testHandleAuthenticationSuccess()
{
$response = (new AuthenticationSuccessHandler(new LexikAuthenticationSuccessHandler($this->getJWTManager('secrettoken'), $this->getDispatcher()), $this->getEncoder(), 'strict', $this->getFalseRememberDeviceResolver(), $this->getDoctrine()))
$response = (new AuthenticationSuccessHandler(new LexikAuthenticationSuccessHandler($this->getJWTManager('secrettoken'), $this->getDispatcher()), $this->getEncoder(), 'strict', $this->getRememberDeviceResolver(false), $this->getDoctrine()))
->handleAuthenticationSuccess($this->getUser());

$this->assertInstanceOf(JsonResponse::class, $response);
Expand All @@ -72,7 +72,7 @@ public function testHandleAuthenticationSuccess()
*/
public function testHandleAuthenticationSuccessWithGivenJWT(string $sameSite)
{
$response = (new AuthenticationSuccessHandler(new LexikAuthenticationSuccessHandler($this->getJWTManager('secrettoken'), $this->getDispatcher()), $this->getEncoder(), $sameSite, $this->getFalseRememberDeviceResolver(), $this->getDoctrine()))
$response = (new AuthenticationSuccessHandler(new LexikAuthenticationSuccessHandler($this->getJWTManager('secrettoken'), $this->getDispatcher()), $this->getEncoder(), $sameSite, $this->getRememberDeviceResolver(false), $this->getDoctrine()))
->handleAuthenticationSuccess($this->getUser(), 'jwt');

$this->assertInstanceOf(JsonResponse::class, $response);
Expand All @@ -95,7 +95,7 @@ public function testRememberDeviceCookieIsSetAfterAuthenticationSuccess()
$request = $this->getRequest();
$token = $this->getToken();

$response = (new AuthenticationSuccessHandler(new LexikAuthenticationSuccessHandler($this->getJWTManager('secrettoken'), $this->getDispatcher()), $this->getEncoder(), 'strict', $this->getTrueRememberDeviceResolver(), $this->getDoctrine()))
$response = (new AuthenticationSuccessHandler(new LexikAuthenticationSuccessHandler($this->getJWTManager('secrettoken'), $this->getDispatcher()), $this->getEncoder(), 'strict', $this->getRememberDeviceResolver(true), $this->getDoctrine()))
->onAuthenticationSuccess($request, $token);

$this->assertInstanceOf(JsonResponse::class, $response);
Expand Down Expand Up @@ -213,29 +213,18 @@ private function getDispatcher()
return $dispatcher;
}

private function getFalseRememberDeviceResolver()
private function getRememberDeviceResolver($status)
{
$rememberDeviceResolver = $this->createMock(RememberDeviceResolver::class);

$rememberDeviceResolver
->expects($this->any())
->method('getRememberDeviceStatus')
->willReturn(false);
->willReturn($status);

return $rememberDeviceResolver;
}

private function getTrueRememberDeviceResolver()
{
$rememberDeviceResolver = $this->createMock(RememberDeviceResolver::class);

$rememberDeviceResolver
->expects($this->any())
->method('getRememberDeviceStatus')
->willReturn(true);

return $rememberDeviceResolver;
}

private function getDoctrine()
{
Expand Down

0 comments on commit 385641e

Please sign in to comment.