FOSUserBundle icon indicating copy to clipboard operation
FOSUserBundle copied to clipboard

The handling of the remember_me does not work in the LoginManager

Open stof opened this issue 14 years ago • 24 comments

The remember me services are private so they are removed from the container when optimizing it. This means that the has checks in the LoginManager will return false even when the remember me is activated for the firewall.

/cc @schmittjoh

stof avatar Aug 07 '12 13:08 stof

How should i fix it?

wiistriker avatar Nov 17 '12 00:11 wiistriker

Good question by @wiistriker. I think this is an issue and should be fixed to allow for persistent login after the user registers and/or a combined registration/login form.

I would gladly help if anyone has an idea on how to fix this now that the remember me services are private.

What is the best practice to set the remember me cookie manually?

kwizzn avatar Nov 27 '12 16:11 kwizzn

@wiistriker I don't know how to fix it, otherwise it would already be in the bundle.

@schmittjoh do you have an idea ?

stof avatar Nov 27 '12 17:11 stof

@stof take a look at https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php#L73 I am not sure, but maybe it will be helpfull

wiistriker avatar Nov 28 '12 00:11 wiistriker

In http://symfony.com/doc/master/components/dependency_injection/advanced.html#aliasing part of docs:

You may sometimes want to use shortcuts to access some services. You can do so by aliasing them and, furthermore, you can even alias non-public services.

so in services.yml:

my.authentication.rememberme.services.simplehash:
        alias: security.authentication.rememberme.services.simplehash.main

and i can get this service and use it. Only problem that we should hardcode .main from our firewall.

Another thing that $rememberMeServices->loginSuccess method inside LoginManager check _remember_me parameter in request, so we need manually set it or use always_remember_me: true

wiistriker avatar Dec 17 '12 10:12 wiistriker

ping @stof @schmittjoh ^^^ what do you think? maybe there is some way to create alias for services inside bundle's extension?

wiistriker avatar Dec 17 '12 11:12 wiistriker

Any update about this?

runcom avatar Jan 12 '13 22:01 runcom

@wiistriker: no it's not possible. it doesn't have access to the full container. It would have to be done in a compiler pass.

ghost avatar Jan 29 '13 07:01 ghost

@jrobeson but it's work

wiistriker avatar Jan 29 '13 07:01 wiistriker

which file? your services.yml? yes it would work there. I was referring to the extension.

ghost avatar Jan 29 '13 08:01 ghost

@wiistriker: see this: http://symfony.com/doc/master/components/dependency_injection/compilation.html#managing-configuration-with-extensions

If you need to manipulate the configuration loaded by an extension then you cannot do it from another extension as it uses a fresh container. You should instead use a compiler pass which works with the full container after the extensions have been processed.

ghost avatar Jan 29 '13 08:01 ghost

+1

noetix avatar Jun 02 '13 07:06 noetix

+1

adurieux avatar Jun 08 '13 12:06 adurieux

+1

devgogo avatar Jun 25 '13 08:06 devgogo

The firewall name is already configured so using a CompilerPass to set the the correct Remember-me service would work right?

The only problem is that the service is always initialized (even when not needed), this can alternatively be solved with lazy loading. But I'm not sure if injecting really results in overhead, how many times is this service initialized?

From what I know the Service is only loaded when its dispatched, and that only happens on resetting and registering.

As a last possibility we can determine the remember-me service and change the public=false to true in a CompilerPass at least until or when lazy-loading is not possible.

Any thoughts on this??

sstok avatar Jun 25 '13 12:06 sstok

up, because it's important to fix the problem :(

afiocre avatar Aug 06 '13 11:08 afiocre

but if not possible. how it working in SonataAdminBundle login?

azatyan avatar Aug 08 '13 16:08 azatyan

This issue relates to the LoginManager class used to log a user in manually.

SonataAdminBundle doesn't do anything in regards to authentication, it relies on a properly configured firewall to handle that.

noetix avatar Aug 08 '13 23:08 noetix

No fix found ?

afiocre avatar Sep 25 '13 13:09 afiocre

To be fair, I haven't spent time to find a fix yet (and nobody has found it annoying enough to contribute a fix)

stof avatar Sep 25 '13 14:09 stof