Symfony 3:未设置Memberme Cookie

Symfony 3:未设置Memberme Cookie,symfony,fosuserbundle,Symfony,Fosuserbundle,在我的Symfony 3应用程序中,我的登录页面位于根url“/”(因此不是“/”登录) 不幸的是,尽管在security.yml中正确配置了“记住我”cookie,但应用程序未设置该cookie: # To get started with security, check out the documentation: # http://symfony.com/doc/current/book/security.html security: encoders: FOS\U

在我的Symfony 3应用程序中,我的登录页面位于根url“/”(因此不是“/”登录)

不幸的是,尽管在security.yml中正确配置了“记住我”cookie,但应用程序未设置该cookie:

# To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
            fos_userbundle:
                id: fos_user.user_provider.username_email

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt|error)|css|images|js)/
            security: false
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager
                check_path: /login_check
                login_path: /
                default_target_path:  /home
                use_forward:    false
                failure_path:   null
                failure_handler: ccdn_user_security.component.authentication.handler.login_failure_handler
                require_previous_session: false
            logout:
                path:   /logout
                target: /
            security: true
            anonymous:
                secret:  "%secret%"
            remember_me:
                secret: "%secret%"
                lifetime: 604800 # 1 week in seconds
                path:     /
                secure: true
            switch_user: true

    access_control:
        - { path: ^/admin, role: ROLE_ADMIN,requires_channel: "%protocol%" }
        - { path: ^/user, roles: ROLE_USER, requires_channel: "%protocol%"}
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: "%protocol%" }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: "%protocol%" }
        - { path: ^/, role: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: "%protocol%" }
我没有任何类型的侦听器设置,这是这篇文章遇到的问题:

我已将FOSUserBundle的SecurityController调整如下:

/**
 * Controllers for Anonymous Index Page
 */
class SecurityController extends BaseController
{
    /**
     * @param Request $request
     *
     * @return Response
     */
    public function loginAction(Request $request)
    {
        $securityContext = $this->container->get('security.authorization_checker');

        if ( $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED') or $securityContext->isGranted('IS_AUTHENTICATED_FULLY') ) {
            return $this->redirect($this->generateUrl('home'));
        }

        $response = parent::loginAction($request);
        return $response;

    }
}
但正如你所看到的,这只是重定向用户,以防他已经登录

但是,FOSUserBundle附带的AuthenticationListener似乎从未被触发

最后,如果您需要,这是登录表单中的“记住我”小部件:

   <div class="checkbox checkbox-css m-b-30">
          <input name="_remember_me" checked type="checkbox" id="remember_me_checkbox" />
          <label for="remember_me_checkbox">Onthoudt mij</label>
   </div>

昂苏特mij
有人知道为什么没有设置cookie吗? 用户在大约20分钟后会自动注销。我猜这是因为PHP会话到期?

根据评论部分回答:

secure:true
表示cookie将仅通过安全连接发送。出于测试目的,您可能需要删除此行,或者检查您的web服务器是否已正确配置为处理
https
流量

确保您通过https访问您的应用程序。我不确定自签名证书是否可能对此产生任何影响。根据Gumbo的回答,它不应该

另一件事:为了防止过早注销,请增加会话超时时间。好的,
记住我
只有在会话期间用户离开时才有帮助

希望这有助于…

根据评论部分回答:

secure:true
表示cookie将仅通过安全连接发送。出于测试目的,您可能需要删除此行,或者检查您的web服务器是否已正确配置为处理
https
流量

确保您通过https访问您的应用程序。我不确定自签名证书是否可能对此产生任何影响。根据Gumbo的回答,它不应该

另一件事:为了防止过早注销,请增加会话超时时间。好的,
记住我
只有在会话期间用户离开时才有帮助


希望这有帮助…

您的服务器(开发服务器?)是否设置为使用SSL/TLS?如果是,您是否通过
https
访问该站点?
下的
安全:true
记住
会引爆cookie,cookie将仅通过安全连接发送…此外,我相信“用户在20分钟左右后自动注销”不会因为修复此问题而消失。您应该在删除安全设置后增加会话超时…@JovanPerovic:true它再次工作(即使我正在运行https)。谢谢!。会话超时我会观察到,但我认为这会修复它。您有服务器(开发服务器)吗设置为使用SSL/TLS?如果是这样,您是否通过
https
访问该站点?
下的
安全:true
记住
将引爆cookie,cookie将仅通过安全连接发送…此外,我相信“用户在20分钟左右后自动注销”不会因为修复此问题而消失。您应该在删除secure:true后增加会话超时…@JovanPerovic它再次工作(即使我正在运行https)。谢谢!。会话超时我会观察,但我认为这将修复它。