I'm currently building a web app, and I want to log in to the app via Google, much like many other websites (including SO) do. However, I'm having difficulty finding a cohesive tutorial that is current and actually works. I was hoping that you, SO, would have some helpful material to assist me. If you guys have any actually useful and cohesive instructions or links to provide, that would be fantastic. Thanks in advance, SO!
EDIT:
So far, I've got a tutorial's code up and running, but whenever I submit it, it seems like it is unable to get an access token. Here ya go:
<?php
include_once("config.php");
include_once("includes/functions.php");
//print_r($_GET);die;
echo("output test ");
if(isset($_REQUEST['code'])){
$gClient->authenticate();
$_SESSION['token'] = $gClient->getAccessToken();
header('Location: ' . filter_var($redirect_url, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['token'])) {
$gClient->setAccessToken($_SESSION['token']);
}
if ($gClient->getAccessToken()) {
$userProfile = $google_oauthV2->userinfo->get();
echo("yep ");
//DB Insert
$gUser = new Users();
$gUser->checkUser('google',$userProfile['id'],$userProfile['given_name'],$userProfile['family_name'],$userProfile['email'],$userProfile['gender'],$userProfile['locale'],$userProfile['link'],$userProfile['picture']);
$_SESSION['google_data'] = $userProfile; // Storing Google User Data in Session
header("location: account.php");
$_SESSION['token'] = $gClient->getAccessToken();
} else {
$authUrl = $gClient->createAuthUrl();
echo("nope ");
}
if(isset($authUrl)) {
echo '<a href="'.$authUrl.'"><img src="images/glogin.png" alt=""/> </a>';
} else {
echo '<a href="logout.php?logout">Logout</a>';
}
?>
I have no idea what's really going on, so any help is appreciated. Thanks.