Friday, December 10, 2021

using Google sign in for our php portal

Following the basic idea explained at
https://phppot.com/php/php-login-script-with-session/
for Google sign-in support for our portal - in our case, it is a postgresql database and not mysql, and we already have the database in place.

We also added a button to sign out of current google account, to make it more user-friendly for people who use multiple google accounts.

<form action="https://accounts.google.com/Logout" method="get" target="logoutframe">
  <input type="submit" value="Sign out from google account" class="w3-button w3-block w3-blue" id="googSO">
</form>

In our case, it was implemented by SC with a function in our User class, $user->processGoogleLogin() so that google_login/login.php has

$google_account_info = $google_oauth->userinfo->get();
$isLoggedIn = $user->processGoogleLogin($google_account_info->email);

and processGoogleLogin() has a select statement with the condition

WHERE u.id = r.user_id AND 
  r.role_id = m.role_id AND
  u.email ilike $1

No comments:

Post a Comment