2

我已经实现了 FOSUserBundle+FOSFacebookBundle,我可以成功注册并登录为普通用户和 facebook 用户。

以 facebook 用户身份登录后,将创建这些会话:

  1. fbm_XXXXXX
  2. fbsr_XXXXXX

模板包含以下代码:

{{ 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 登录按钮弹出窗口时,我填写了表单,我的模板中的 FB 登录按钮更改为“注销”,我等待 5 秒直到重定向。重定向后,我已正确登录,但按钮再次更改为“登录”(而不是“注销”),我无法强制正确注销 Facebook。

有什么想法可能是错的吗?

已解决 应该有'status': true争论facebook_initialize

配置 安全性.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 捆绑包的文档。

4

1 回答 1

2

应该有'status': true争论facebook_initialize

{{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();', 'status': true }) }}

配置 安全性.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 捆绑包的文档。

于 2012-11-01T13:57:11.450 回答