Symfony2 中的 OpenID 与 FOSUserBundle

发布于 2024-12-11 14:07:34 字数 400 浏览 1 评论 0原文

我正在尝试在此项目的基础上将 openID 与 FOSUserBundle 集成: 不幸的

是,其中存在错误。其中一个是配置问题(对于想要尝试的人来说): src/SC/UsersBundle/Resources/config/routing/security.xml 中的第 8 行应为 SCUsersBundle:Security:login

这暗示该项目从未完成。解决后,我得到“SQLSTATE[23000]:违反完整性约束:1048列'电子邮件'不能为空” 这似乎是由于 User 对象是序列化的,并且由于某种原因 FOSUserBundle 在“序列化”方法中不包含电子邮件。

之后,以及一些其他属性被包含到重写方法(包括“id”)中,系统仍然希望创建一个新条目,而不是更新现有条目。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伤感在游骋 2024-12-18 14:07:34

在 FOSUserBundle 的 InteractiveLoginListener 中反序列化用户对象时出现问题。现在,您可以手动设置安全令牌并将用户重定向到另一个页面,而不是将其发送回 fos_user_security_check。

例如,不要这样做:

// 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)));

执行以下操作:

// 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'));

其中“authenticated_user_dashboard”是您希望用户最终访问的任何内部登录页面。

请注意,由于未调用 FOSUserBundle 的 InteractiveLoginListener::onSecurityInteractiveLogin(),因此不会自动更新上次登录时间。

这是 makasim 正在调查的已知问题:https://github.com/formapro/FpOpenIdBundle/issues /5

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

半岛未凉 2024-12-18 14:07:34

master 分支包含该问题的修复

The master branch contains fixes for the issue

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文