3
votes

I am trying to integrate openID with the FOSUserBundle on the basis of this project: http://symfony2bundles.org/diegogd/fosuser-fpopenid

Unfortunately, there them to be errors. One was a configuration issue (for the people who want to try): Line 8 in src/SC/UsersBundle/Resources/config/routing/security.xml should read SCUsersBundle:Security:login

That hints that the project was never completed. After that is solved, I get "SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'email' cannot be null" This seems to be due to the fact that the User object is serialized and for some reason the FOSUserBundle does not include email in the "serialize" method.

After that and some other properties are included into an overriding method (including "id"), the system still wants to create a new entry instead of updating the existing one.

Any ideas?

2
Notice: Don't use fpOpenID anymore if you want to keep your sanity. It's not been updated for a year and it'll break on current PHP/Symfony2 versions because vital methods like getExtraInformation() have been deprecated.Tom

2 Answers

1
votes

There is a problem with unserializing user objects in FOSUserBundle's InteractiveLoginListener. For now you can manually set the security token and redirect users to a another page rather than sending them back to fos_user_security_check.

For example, instead of this:

// IMPORTANT: It is required to set a user to token (UserInterface)
$newToken = new OpenIdToken($token->getOpenIdentifier(), $user->getRoles());
$newToken->setUser($user);

$tokenPersister->set($newToken);

// IMPORTANT: It is required make a redirect to `login_check` with parameter `openid_approved`
return $this->redirect($this->generateUrl('login_check_route', array('openid_approved' => 1)));

Do this:

// IMPORTANT: It is required to set a user to token (UserInterface)
$newToken = new OpenIdToken($token->getOpenIdentifier(), $user->getRoles());
$newToken->setUser($user);

$tokenPersister->set($newToken);
$this->get('security.context')->setToken($newToken);

return $this->redirect($this->generateUrl('authenticated_user_dashboard'));

Where "authenticated_user_dashboard" is whatever internal landing page you want users to end up on.

Note that because FOSUserBundle's InteractiveLoginListener::onSecurityInteractiveLogin() is not called, last login time will not be updated automatically.

This is a known issue that makasim is investigating: https://github.com/formapro/FpOpenIdBundle/issues/5

0
votes

The master branch contains fixes for the issue