Symfony2:使用两个不同的用户提供程序登录网站时无法模拟用户 [英] Symfony2: unable to impersonate user when website log-in using two different user providers

查看:72
本文介绍了Symfony2:使用两个不同的用户提供程序登录网站时无法模拟用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站中,用户可以使用简单帐户(在我的网站中创建,配置为MY_OWN_USER提供程序,通过电子邮件选择用户)登录,也可以使用Facebook登录(通过fosfacebook捆绑包集成)登录.

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).

当我尝试模拟用户时(附加链接'...?_ switch_user=demo@demo.com',如

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

安全性.警告:切换用户失败:用户未在Facebook上通过身份验证"

我检查了 Symfony \ Component \ Security \ Http \ Firewall \ SwitchUserListener ,看起来默认情况下它不是MY_OWN_USER提供程序,而是fosfacebook提供程序,它试图通过facebook_id选择用户(如果我附加链接)与'...?_ switch_user = FACEBOOK_ID'-切换用户正常工作!)

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!)

那么如何使SwitchUserListener能够获得MY_OWN_USER提供程序,该提供程序通过电子邮件而不是通过Facebook ID选择用户?

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

推荐答案

security.yml中的防火墙配置中配置模拟时,可以指定应使用哪个提供程序来查找被模拟的用户(参考).例如:

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

希望这会有所帮助!

这篇关于Symfony2:使用两个不同的用户提供程序登录网站时无法模拟用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆