本文介绍了Symfony2,表单,username_parameter和防火墙参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用实现 SimpleFormAuthenticationInterface .

但是,由于表单输入方式name="form[username]"的原因,我无法将其传递给username_parameter并传递给createToken.有没有办法做到这一点,或者我必须编写自己的身份验证监听器?

However, because of the way forms have their input name="form[username]" I'm not able to pass that to the username_parameter and into createToken. Is there a way to do this or will I have to write my own Authentication Listener?

这是我的配置:

firewalls:
  secured_area:
        provider: UserRepository
        pattern: ^/user
          simple_form:
             username_parameter:
             password_parameter:
             authenticator: UserAuthenticator
             login_path:  /login
             check_path:  /user/auth

推荐答案

RequestSymfony\Component\HttpFoundation\ParameterBag显然解析了security.yml配置中html数组形式的参数

Apparently Request's Symfony\Component\HttpFoundation\ParameterBag resolves parameters that are of html array form in the security.yml configuration

下: https://github.com /symfony/symfony/blob/2.4/src/Symfony/Component/HttpFoundation/ParameterBag.php#L103-L150

因此您可以使用并做类似的事情:

So you can use and do something like:

firewalls:
  secured_area:
        provider: UserRepository
        pattern: ^/user
          simple_form:
             username_parameter: MyForm[username]
             password_parameter: MyForm[password]
             authenticator: UserAuthenticator
             login_path:  /login
             check_path:  /user/auth

这篇关于Symfony2,表单,username_parameter和防火墙参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 08:27