PHP 中的 OpenID 自动登录 Janrain 示例

发布于 2024-09-18 00:09:39 字数 178 浏览 4 评论 0原文

我希望我的网站能够自动检测用户是否登录谷歌。如果是,它会检查数据库以查看它们是否已经注册。如果他们注册了,就会将他们登录到我的网站。否则,它会将他们重定向到登录页面。

我认为这可能是实验性的 x-has-session 但我不知道如何实现它。我正在使用 JanRain OpenID PHP 库。

回复已采纳!

I want my website to automatically detect if a user is logged into google. If they are, it checks the database to see if they are already registered. If they are registered, it logs them in to my site. Otherwise, it redirects them to the login page.

I think it might be the experimental x-has-session but I've no idea how to implement it. I'm using the JanRain OpenID PHP Library.

Responses appriciated!

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

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

发布评论

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

评论(1

你没皮卡萌 2024-09-25 00:09:39

我刚刚使用 JanRain 和 Zend Framework 编写了这个确切的东西,也使用 Facebook 完成了它。

  1. 您应该创建一个使用用户名、电子邮件和密码的普通注册系统。并使用 cookie 来保存令牌,以及基于正常会话的登录,在登录表单上实现某种“保持登录”功能。
  2. 然后创建您的 Google 登录链接,该链接链接到一个使用 JanRain OpenId 与 https://www.google.com/accounts/o8/id 进行通信的脚本。
  3. 从您从 Google 获得的响应中,您可以获取他们的名字、姓氏和电子邮件,使用它们来填充用户表,就像使用普通注册用户一样。但在这种情况下,他们的用户名和密码将为 NULL。当该用户位于表中时,请设置您的“保持登录”cookie。
  4. 现在,当 Google 用户返回时,他们已经使用正常的“保持登录”功能登录。
  5. 您的“注销”页面应清除会话并删除“保持登录”cookie 令牌。

您可能需要考虑当某人使用 Google 登录、然后注销并稍后使用 Google 重新登录时会发生什么。您需要在用户表中检查该用户,并将用户行与 Google 的结果进行匹配,而不是每次都注册一个新用户。

I have just written this exact thing using JanRain and Zend Framework, also done it with Facebook.

  1. You should create a normal registration system which uses a username, email and password. And implement some sort of Stay Logged In functionality on your log in form using a cookie to persist a token, as well as normal Session based login.
  2. Then create your Google log in link, which links to a script which talks to https://www.google.com/accounts/o8/id using JanRain OpenId.
  3. From the response you get from Google you can get their first name, last name and email, use this to populate the user table as you would with a normal registered user. But in this instance their username and password would be NULL. When this user is then in the table set up your Stay Logged In cookie.
  4. Now when the Google user returns they are already logged in using your normal Stay Logged In functionality.
  5. Your Log Out page should clear the session and remove the Stay Logged In cookie token.

You may want to consider what happens when someone logs in using Google, then logs out and then logs back in using Google at a later date. You will need to check for that user in the user table and match the user row up with the result from Google, rather than registering a new user each time.

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