小编dom*_*kat的帖子

使用新身份验证方法的 Symfony 简单登录表单不起作用

我在设置新的 symfony 应用程序时遇到问题,我确信它与新的基于身份验证器的安全系统有关。

  1. 我安装了一个新的 symfony 应用程序,版本 5.3.6。
  2. 安装安全包composer require symfony/security-bundle(https://symfony.com/doc/current/security.html)。按照那里的所有步骤进行操作。
  3. 之后,我想按照本指南构建一个简单的登录表单: https: //symfony.com/doc/current/security/form_login_setup.html。php bin/console make:auth我像往常一样执行了生成所有文件并更新我的 security.yml 的命令。在这里,我注意到该命令没有生成 Guard 身份验证器(因为我知道它已经过时了),而是生成了新的(https://symfony.com/doc/current/security/authenticator_manager.html)。
  4. 之后,我转到我的 /login 页面,输入凭据并提交表单。页面重新加载,什么也没有。没有错误消息,我仍然没有经过身份验证。我没有执行任何其他步骤,因为它应该按原样工作?好吧,至少旧的 Guard 身份验证是这样工作的。然而,这个新的身份验证系统似乎不起作用。我错过了什么吗?

我的文件:

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)

php authentication symfony

5
推荐指数
1
解决办法
4276
查看次数

标签 统计

authentication ×1

php ×1

symfony ×1