Symfony2: unable to impersonate user when website log-in using two different user providers

对着背影说爱祢 提交于 2020-01-05 04:44:51

问题


In my website user can log-in with simple account (created in my website, configured MY_OWN_USER provider, which selects user by email) or using facebook log-in (integrated through fosfacebook bundle).

When i'm trying to impersonate user (appending link '...?_switch_user=demo@demo.com', like described in Symfony2 documentation) Symfony2 logs such warning:

security.WARNING: Switch User failed: "The user is not authenticated on facebook"

I've checked Symfony\Component\Security\Http\Firewall\SwitchUserListener and looks like by default it gets not MY_OWN_USER provider but fosfacebook provider which tries to select user by facebook_id (if i append link with '...?_switch_user=FACEBOOK_ID' - switch user works correctly!)

So how to make that SwitchUserListener would get MY_OWN_USER provider which selects user by email not by facebook id?


回答1:


When configuring impersonation in your firewall config in security.yml, you can specify which provider should be used to find the user who is being impersonated (ref). For example:

switch_user:
    provider: MY_OWN_USER

Hope this helps!



来源:https://stackoverflow.com/questions/12916510/symfony2-unable-to-impersonate-user-when-website-log-in-using-two-different-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!