FriendsOfSymfony / FOSFacebookBundle

NOT MAINTAINED - see https://github.com/hwi/HWIOAuthBundle
321 stars 140 forks source link

fosUser + fosFacebook login problem #109

Open Sgnx opened 12 years ago

Sgnx commented 12 years ago

Hi, I have a problem with admin and users and I got confused with all that. I've already installed sonata admin(with fos user) and there everything works fine.

But i have a problem with facebook bundle on frontend.

My website: http://sgnx.lh.pl/web/app_dev.php

When i click the login button and fill the facebook requirements the button is changing to logout, but when i change the page it changes back to login again. I think there is a problem with my configuration ;/

Below i present my configuration.

My security:

security:
    providers:
          my_fos_facebook_provider:
              id: my.facebook.user
          fos_userbundle:
            id: fos_user.user_manager
    encoders:
        "FOS\UserBundle\Model\UserInterface": sha512
    firewalls:
           admin:
            switch_user:        true
            context:            user
            pattern:      /admin(.*)
            form_login:
                provider:       fos_userbundle
                login_path:     /admin/login
                use_forward:    false
                check_path:     /admin/login_check
                failure_path:   null
                use_referer:    true
                default_target_path: /admin/dashboard
            logout:
                path:           /admin/logout
                target:         /admin/login
            anonymous:    true          
           public:
              # since anonymous is allowed users will not be forced to login
              pattern:  .*
              fos_facebook:
                  app_url: "http://apps.facebook.com/krakowforfun/"
                  server_url: "http://localhost/facebookApp/"
                  login_path: ^/login
                  check_path: ^/login_check
                  default_target_path: /
                  provider: my_fos_facebook_provider
              anonymous: true
              logout:
                  handlers: ["fos_facebook.logout_handler"]
           main:            
              pattern:  .*
              form_login:
                provider:       fos_userbundle
                login_path:     /login
                use_forward:    false
                check_path:     /login_check
                failure_path:   null
              logout:       true
              anonymous:    true
    access_control:
        # URL of FOSUserBundle which need to be available to anonymous users
        - { path: ^/_wdt, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/_profiler, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }

        # -> custom access control for the admin area of the URL
        - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/login-check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        # -> end

        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }

        # Secured part of the site
        # This config requires being logged for the whole site and having the admin role for the admin part.
        # Change these rules to adapt them to your needs
        - { path: ^/secured/.*, role: [IS_AUTHENTICATED_FULLY] }    
        - { path: ^/admin, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] }
        - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }    
    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_SONATA_ADMIN, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
        SONATA:
            - ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT
    acl:
        connection: default

my config:

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Acme\UserBundle\Entity\User
fos_facebook:
      file:   %kernel.root_dir%/../vendor/facebook/src/base_facebook.php
      alias:  facebook
      app_id: "here is my id"
      secret: "here is my secret"
      cookie: true
      permissions: [email, user_birthday, user_location]

my routing:

fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_profile:
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    prefix: /profile

fos_user_register:
    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
    prefix: /register

fos_user_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting
fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /profile

_security_check:
      pattern:  /login_check
_security_logout:
      pattern:  /logout

_facebook_secured:
    pattern: /secured/
    defaults: { _controller: AcmeDemoBundle:News:index  }

If anyone can help me i will appreciate it.

TacoV commented 12 years ago

I think this issue is not due to your config, but a duplicate of #76. You can use the workaround presented there for now.