我在设置新的 symfony 应用程序时遇到问题,我确信它与新的基于身份验证器的安全系统有关。
composer require symfony/security-bundle(https://symfony.com/doc/current/security.html)。按照那里的所有步骤进行操作。php bin/console make:auth我像往常一样执行了生成所有文件并更新我的 security.yml 的命令。在这里,我注意到该命令没有生成 Guard 身份验证器(因为我知道它已经过时了),而是生成了新的(https://symfony.com/doc/current/security/authenticator_manager.html)。我的文件:
LoginFormAuthenticator.php
class LoginFormAuthenticator extends AbstractLoginFormAuthenticator{
use TargetPathTrait;
public const LOGIN_ROUTE = 'app_login';
private UrlGeneratorInterface $urlGenerator;
public function __construct(UrlGeneratorInterface $urlGenerator)
{
$this->urlGenerator = $urlGenerator;
}
public function authenticate(Request $request): PassportInterface
{
$email = $request->request->get('email', '');
$request->getSession()->set(Security::LAST_USERNAME, $email);
return new Passport(
new UserBadge($email),
new PasswordCredentials($request->request->get('password', '')),
[
new …Run Code Online (Sandbox Code Playgroud)