Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook Bundle and Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::serialize() must return a string or NULL
    primarykey
    data
    text
    <p>I've follow the doc of the bundle (tagged version to work with symfony 2.012): </p> <p><a href="http://knpbundles.com/FriendsOfSymfony/FOSFacebookBundle" rel="nofollow">http://knpbundles.com/FriendsOfSymfony/FOSFacebookBundle</a></p> <p>So i've got this error when i intend to log on my website now : </p> <p>Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::serialize() must return a string or NULL</p> <p>I the logon with facebook work but it's doesn't log me on my website here is my configs files :</p> <p>//security.yml </p> <pre><code>security: factories: - "%kernel.root_dir%/../vendor/bundles/FOS/FacebookBundle/Resources/config/security_factories.xml" providers: fos_userbundle: id: fos_user.user_manager my_fos_facebook_provider: id: my.facebook.user firewalls: main: pattern: .* fos_facebook: app_url: "http://apps.facebook.com/psiware/" server_url: "http://localhost/keepinsport/web/app_dev.php/ks" login_path: ^/login check_path: ^/login_check$ default_target_path: / provider: my_fos_facebook_provider form_login: provider: fos_userbundle login_path: /login use_forward: false check_path: /login_check failure_path: null default_target_path: /ks logout: path: /logout target: / handlers: ["fos_facebook.logout_handler"] anonymous: true remember_me: key: aSecretKey #Correspond à un mois lifetime: 2592000 path: / domain: ~ encoders: Symfony\Component\Security\Core\User\User: plaintext FOS\UserBundle\Model\UserInterface: sha512 # C'est ici que tout se passe : qui a accès à quoi ? access_control: - { path: ^/$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/admin/, role: ROLE_ADMIN } - { path: ^/ks, role: ROLE_USER } - { path: ^/facebook/, role: [ROLE_FACEBOOK] } - { path: ^/.*, role: [IS_AUTHENTICATED_ANONYMOUSLY] } role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] </code></pre> <p>//my config.yml</p> <pre><code>fos_facebook: file: %kernel.root_dir%/../vendor/facebook/src/base_facebook.php alias: facebook app_id: 106071199501870 secret: 219af5b2792ea6267de3cf1017f91c1a cookie: true permissions: [email, user_birthday, user_location] services: my.facebook.user: class: Ks\UserBundle\Security\User\Provider\FacebookProvider arguments: facebook: "@fos_facebook.api" userManager: "@fos_user.user_manager" validator: "@validator" </code></pre> <p>//My login.html.twig</p> <pre><code>{{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();'}) }} {{ facebook_login_button({'autologoutlink': true}) }} &lt;script&gt; function goLogIn(){ window.location = "{{ path('_security_check') }}"; } function onFbInit() { if (response.session || response.authResponse) { setTimeout(goLogIn, 500); } else { window.location.href = "{{ path('_security_logout') }}"; } } &lt;/script&gt; </code></pre> <p>//My User entity</p> <pre><code> /** * @var string * * @ORM\Column(name="firstname", type="string", length=255) */ protected $firstname; /** * @var string * * @ORM\Column(name="lastname", type="string", length=255) */ protected $lastname; /** * @var string * * @ORM\Column(name="facebookId", type="string", length=255) */ protected $facebookId; public function serialize() { return serialize(array($this-&gt;facebookID, parent::serialize())); } public function unserialize($data) { list($this-&gt;facebookID, $parentData) = unserialize($data); parent::unserialize($parentData); } /** * @return string */ public function getFirstname() { return $this-&gt;firstname; } /** * @param string $firstname */ public function setFirstname($firstname) { $this-&gt;firstname = $firstname; } /** * @return string */ public function getLastname() { return $this-&gt;lastname; } /** * @param string $lastname */ public function setLastname($lastname) { $this-&gt;lastname = $lastname; } /** * Get the full name of the user (first + last name) * @return string */ public function getFullName() { return $this-&gt;getFirstName() . ' ' . $this-&gt;getLastname(); } /** * @param string $facebookId * @return void */ public function setFacebookId($facebookId) { $this-&gt;facebookId = $facebookId; $this-&gt;setUsername($facebookId); $this-&gt;salt = ''; } /** * @return string */ public function getFacebookId() { return $this-&gt;facebookId; } /** * @param Array */ public function setFBData($fbdata) { if (isset($fbdata['id'])) { $this-&gt;setFacebookId($fbdata['id']); $this-&gt;addRole('ROLE_FACEBOOK'); } if (isset($fbdata['first_name'])) { $this-&gt;setFirstname($fbdata['first_name']); } if (isset($fbdata['last_name'])) { $this-&gt;setLastname($fbdata['last_name']); } if (isset($fbdata['email'])) { $this-&gt;setEmail($fbdata['email']); } } </code></pre> <p>//My facebookProvider.php</p> <pre><code>class FacebookProvider implements UserProviderInterface </code></pre> <p>{ /** * @var \Facebook */ protected $facebook; protected $userManager; protected $validator;</p> <pre><code>public function __construct(BaseFacebook $facebook, $userManager, $validator) { $this-&gt;facebook = $facebook; $this-&gt;userManager = $userManager; $this-&gt;validator = $validator; } public function supportsClass($class) { return $this-&gt;userManager-&gt;supportsClass($class); } public function findUserByFbId($fbId) { return $this-&gt;userManager-&gt;findUserBy(array('facebookId' =&gt; $fbId)); } public function loadUserByUsername($username) { $user = $this-&gt;findUserByFbId($username); try { $fbdata = $this-&gt;facebook-&gt;api('/me'); } catch (FacebookApiException $e) { $fbdata = null; } if (!empty($fbdata)) { if (empty($user)) { $user = $this-&gt;userManager-&gt;createUser(); $user-&gt;setEnabled(true); $user-&gt;setPassword(''); } // TODO use http://developers.facebook.com/docs/api/realtime $user-&gt;setFBData($fbdata); if (count($this-&gt;validator-&gt;validate($user, 'Facebook'))) { // TODO: the user was found obviously, but doesnt match our expectations, do something smart throw new UsernameNotFoundException('The facebook user could not be stored'); } $this-&gt;userManager-&gt;updateUser($user); } if (empty($user)) { throw new UsernameNotFoundException('The user is not authenticated on facebook'); } return $user; } public function refreshUser(UserInterface $user) { if (!$this-&gt;supportsClass(get_class($user)) || !$user-&gt;getFacebookId()) { throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); } return $this-&gt;loadUserByUsername($user-&gt;getFacebookId()); } </code></pre> <p>}</p> <p>I don't understand why the serialisation doesnt work thanks for your answers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload