我已经实施了FOSUserBundle + FOSFacebookBundle,我可以成功注册并以普通用户和Facebook用户身份登录。
以facebook用户身份登录后,会创建以下会话:
模板包含以下代码:
{{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();'}) }}
{{ facebook_login_button({'autologoutlink': true}) }}
<script>
function goLogIn(){
window.location = "{{ path('fos_facebook_security_check') }}";
}
function onFbInit() {
if (typeof(FB) != 'undefined' && FB != null ) {
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.session || response.authResponse) {
setTimeout(goLogIn, 5000);
} else {
window.location = "{{ path('fos_user_security_logout') }}";
}
});
}
}
</script>
当我单击FB-login按钮弹出窗口时,我完成表单,模板中的FB-login按钮变为“logout”,我等待5秒直到重定向。 重定向后,我已正确登录,但按钮再次变为“登录”(而不是“注销”),我无法强制正确登录。
任何想法可能出错?
解决
'status': true
个参数中应该有facebook_initialize
。
配置 security.yml
services:
my.facebook.user:
class: Strict\UserBundle\Security\User\Provider\FacebookProvider
arguments:
facebook: "@fos_facebook.api"
userManager: "@fos_user.user_manager"
validator: "@validator"
container: "@service_container"
strict_user.my_provider:
class: Strict\UserBundle\Security\User\Provider\StrictProvider
public: false
arguments: ["@fos_user.user_manager"]
security:
factories:
- "%kernel.root_dir%/../vendor/bundles/FOS/FacebookBundle/Resources/config/security_factories.xml"
providers:
chain_provider:
providers: [fos_userbundle, my_fos_facebook_provider]
fos_userbundle:
id: strict_user.my_provider
my_fos_facebook_provider:
id: my.facebook.user
encoders:
"FOS\UserBundle\Model\UserInterface": sha512
firewalls:
public:
pattern: ^/
fos_facebook:
app_url: "http://www.facebook.com/apps/application.php?id="
server_url: "http://localhost/web/app_dev.php"
login_path: fos_user_security_login
check_path: fos_facebook_security_check
default_target_path: homepage
provider: my_fos_facebook_provider
form_login:
login_path: fos_user_security_login
check_path: fos_user_security_check
provider: fos_userbundle
anonymous: true
logout:
path: fos_user_security_logout
target: homepage
对于其余文件,请检查用户和Facebook捆绑包的文档。
答案 0 :(得分:2)
'status': true
个参数中应该有facebook_initialize
。
{{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();', 'status': true }) }}
<强>配置强> security.yml
services:
my.facebook.user:
class: Strict\UserBundle\Security\User\Provider\FacebookProvider
arguments:
facebook: "@fos_facebook.api"
userManager: "@fos_user.user_manager"
validator: "@validator"
container: "@service_container"
strict_user.my_provider:
class: Strict\UserBundle\Security\User\Provider\StrictProvider
public: false
arguments: ["@fos_user.user_manager"]
security:
factories:
- "%kernel.root_dir%/../vendor/bundles/FOS/FacebookBundle/Resources/config/security_factories.xml"
providers:
chain_provider:
providers: [fos_userbundle, my_fos_facebook_provider]
fos_userbundle:
id: strict_user.my_provider
my_fos_facebook_provider:
id: my.facebook.user
encoders:
"FOS\UserBundle\Model\UserInterface": sha512
firewalls:
public:
pattern: ^/
fos_facebook:
app_url: "http://www.facebook.com/apps/application.php?id="
server_url: "http://localhost/web/app_dev.php"
login_path: fos_user_security_login
check_path: fos_facebook_security_check
default_target_path: homepage
provider: my_fos_facebook_provider
form_login:
login_path: fos_user_security_login
check_path: fos_user_security_check
provider: fos_userbundle
anonymous: true
logout:
path: fos_user_security_logout
target: homepage
对于其余文件,请检查用户和Facebook捆绑包的文档。