简体   繁体   中英

OpenID with FOSUserBundle in Symfony2

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?

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

主分支包含该问题的修复程序

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM