Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 "This authentication method requires a session" error on login check

I have been trying to implement a simple form login following instructions in Symfony's book but I'm stuck at login. Whenever I try to login I get a "This authentication method requires a session" error thrown from AbstractAuthenticationListener::handle. I've searched Symfony's book and cookbook and Google but found no answer or even some related issue.

Is this me misunderstanding something in the book or maybe a misconfiguration of my server?

If you need code extract don't mind to ask...

security.yml

security:
  encoders:
    Common\Bundle\UserBundle\Entity\User:
      algorithm: bcrypt
      cost:      10
  providers:
    main:
      entity: { class: CommonUserBundle:User }
  firewalls:
    main:
      pattern:   ^/
      provider:  main
      anonymous: ~
      simple_form:
        authenticator: simple_authenticator
        login_path:   /Connexion
        check_path:   /Connexion/verifier
      logout:
        path:   /Deconnexion
        target: /
      remember_me:
        key:      "%secret%"
        lifetime: 2592000
        path:     /
        domain:   ~

config.yml

  framework:
    secret:    "%secret%"
    fragments: { path: /_fragment }
    router:
      resource: "%kernel.root_dir%/config/routing.yml"
    validation:
      enable_annotations: true
    templating:
      engines: ['twig']
    default_locale: "%locale%"
    http_method_override: true
like image 682
WillysMD Avatar asked Aug 11 '14 16:08

WillysMD


2 Answers

You need to enable PHP sessions to keep users logged. Your config.yml file lets appear it's not enabled, add a session section inside framework root level :

Here is default config :

framework:
    # ...
    session: ~

Have a look to the official documentation to learn how to configure session storage : http://symfony.com/doc/current/reference/configuration/framework.html#session

like image 172
AlterPHP Avatar answered Sep 29 '22 05:09

AlterPHP


For Symfony 4

Edit config/packages/framework.yaml

And add

framework:
    session:
        handler_id: ~
like image 37
Mykhailo Avatar answered Sep 29 '22 03:09

Mykhailo