0

Using symfony2.1 und FOSFacebookBundle:

If the user is typing www.example.com, e.g. the user closed his browser, then I want to do a redirect to www.example.com/secured if he is still authenticated.

I can not get in the indexAction if the user is authenticated.

My Security.yml:

security:
encoders:
    Symfony\Component\Security\Core\User\User: plaintext

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

providers:
    in_memory:
        memory:
            users:
                user:  { password: userpass, roles: [ 'ROLE_USER' ] }
                admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
    my_fos_facebook_provider:
            id: my.facebook.user
                 //How can I add here a ROLE_USER?

firewalls:

     //standard thing from FosFacebookBundle

access_control:
    - { path: ^/, roles: [IS_AUTHENTICATED_ANONYMOUSLY]  } 

My indexAction:

if( $this->container->get('security.context')
    ->isGranted('IS_AUTHENTICATED_FULLY') ){
   echo 'asdf'; //this is working in the secured area www.example.com/secured/
}

My error message: The security context contains no authentication token. One possible reason may be that there is no firewall configured for this URL.

In the secured area the user has no ROLES. How can I change it?

What is wrong?

UPDATE

namespace Frontend\FbAccountBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

 /**
 * User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity
 */
class User
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="bigint", nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $id;

/**
 * @var integer
 *
 * @ORM\Column(name="facebook_id", type="bigint", nullable=false)
 */
private $facebookId;
/**
 * @param Array
 */
public function setFBData($fbdata)
{
    if (isset($fbdata['id'])) {
        $this->setFacebookId($fbdata['id']);
        $this->addRole('ROLE_FACEBOOK');
    }
}

security.yml:

services:
my.facebook.user:
    class: Frontend\FbAccountBundle\Security\User\Provider\FacebookProvider
    arguments:
        facebook: "@fos_facebook.api"
        userManager: "@fos_user.user_manager"
        validator: "@validator"
        container: "@service_container"
craphunter
  • 961
  • 2
  • 13
  • 34

1 Answers1

0

You need to write a User Provider to add the role to your User. This is covered in the FOSFacebookBundle documentation. Take a look at the service definition and the setFBData method on the User entity near the bottom of the page. That should give you a solid start.

Integration with FOSUserBundle

Ken Hannel
  • 2,718
  • 17
  • 20