From e59bed36db3936cda8380e189a4b5b53bcf8c247 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Wed, 25 Jan 2023 22:29:57 +0100 Subject: [PATCH] feat(upgrade): add compliance with symfony 6.2 --- composer.json | 2 +- config/packages/scheb_2fa.yaml | 3 +-- config/packages/security.yaml | 7 +------ src/Entity/User.php | 28 ++++++++++++++++++---------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 068dc12..f289b59 100644 --- a/composer.json +++ b/composer.json @@ -63,7 +63,7 @@ "extra": { "symfony": { "allow-contrib": false, - "require": "6.0.*" + "require": "6.2.*" } } } diff --git a/config/packages/scheb_2fa.yaml b/config/packages/scheb_2fa.yaml index e143e82..5774406 100644 --- a/config/packages/scheb_2fa.yaml +++ b/config/packages/scheb_2fa.yaml @@ -1,10 +1,9 @@ # See the configuration reference at https://github.com/scheb/2fa/blob/master/doc/configuration.md scheb_two_factor: - google: + totp: enabled: true issuer: "Murph" server_name: - digits: 6 window: 1 template: "@Core/auth/2fa.html.twig" security_tokens: diff --git a/config/packages/security.yaml b/config/packages/security.yaml index f35b7a4..5edaa71 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -1,8 +1,4 @@ security: - encoders: - App\Entity\User: - algorithm: auto - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers enable_authenticator_manager: true # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords @@ -28,8 +24,7 @@ security: two_factor: auth_form_path: 2fa_login # The route name you have used in the routes.yaml check_path: 2fa_login_check # The route name you have used in the routes.yaml - guard: - authenticators: + custom_authenticators: - App\Core\Authenticator\LoginFormAuthenticator form_login: login_path: auth_login diff --git a/src/Entity/User.php b/src/Entity/User.php index c0e5138..cd9c7a2 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -6,9 +6,11 @@ use App\Core\Doctrine\Timestampable; use App\Core\Entity\EntityInterface; use App\Repository\UserRepository; use Doctrine\ORM\Mapping as ORM; -use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; +use Scheb\TwoFactorBundle\Model\Totp\TwoFactorInterface; +use Scheb\TwoFactorBundle\Model\Totp\TotpConfiguration; +use Scheb\TwoFactorBundle\Model\Totp\TotpConfigurationInterface; #[ORM\Entity(repositoryClass: UserRepository::class)] #[ORM\HasLifecycleCallbacks] @@ -160,24 +162,30 @@ class User implements PasswordAuthenticatedUserInterface, UserInterface, TwoFact return null !== $this->getTotpSecret(); } - public function isGoogleAuthenticatorEnabled(): bool - { - return $this->isTotpAuthenticationEnabled(); - } - - public function getGoogleAuthenticatorUsername(): string + public function getTotpAuthenticationUsername(): string { return $this->getEmail(); } - public function getGoogleAuthenticatorSecret(): ?string + public function getTotpAuthenticationSecret(): ?string { return $this->getTotpSecret(); } - public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void + public function setTotpAuthenticationSecret(?string $totpAuthenticatorSecret): void { - $this->setTotpSecret($googleAuthenticatorSecret); + $this->setTotpSecret($totpAuthenticatorSecret); + } + + public function getTotpAuthenticationConfiguration(): ?TotpConfigurationInterface + { + // You could persist the other configuration options in the user entity to make it individual per user. + return new TotpConfiguration( + $this->getTotpAuthenticationSecret(), + TotpConfiguration::ALGORITHM_SHA1, + 20, + 6 + ); } public function getPasswordRequestedAt(): ?\DateTimeInterface