OpenID Autologin Janrain Example in php

I want my site to automatically detect that a user has registered with Google. If they are, he checks the database to make sure they are already registered. If they are registered, he registers them on my site. Otherwise, it redirects them to the login page.

I think it might be an experimental x-has-session, but I don't know how to implement it. I am using the OpenID PHP library from JanRain.

The answers are appriciated!

+4
source share
1 answer

I just wrote this exact thing using JanRain and Zend Framework, also did it using Facebook.

  • You should create a regular registration system that uses a username, email address and password. And implement some β€œStay logged in” function in the form of logging in using a cookie to save the token, as well as for a regular login based on the session.
  • Then create your google login link that links to a script that talks to https://www.google.com/accounts/o8/id using the JanRain OpenId function.
  • From the response you receive from Google, you can get your first name, last name and email address, using this to fill out the user table in the same way as with a regular registered user. But in this case, their username and password will be NULL. When this user is in the table, set the Stay Logged In cookie.
  • Now that the Google user is back, they are already logged in using your usual login features.
  • On the Logout page, you must clear the session and remove the Save Log token.

You might want to think about what happens when someone logs in with Google, then logs out and then logs in again with Google. You will need to check this user in the user table and match the user string with the Google result, and not register a new user each time.

+1
source

All Articles