I've followed the quickstart guide to setup a basic website in PHP to use the Google Identity Toolkit. The widget on the index.php page displays the 'sign-in' button. When pressed I'm taken to the gitkit.php page and prompted to enter my email address. After doing so I'm taken to a Google site to put in my password. After I do so I'm redirected back to my website but the widget still says 'login' and the index.php page does not recognise that I have signed in. No error messages are displayed through the sign-in process. Have spent a fair bit of time trying to diagnose but not getting anywhere. Hoping somebody can point me in the right direction.
I have setup the hosts file on my computer to point briansfakedomainname.com to a webserver accessible on my LAN.
My index.php page:
<!DOCTYPE html>
<html>
<head>
<!-- 1: Load the Google Identity Toolkit helpers -->
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .'/identity-toolkit-php-master/vendor/google/apiclient/src');
require_once __DIR__ . '/identity-toolkit-php-master/vendor/autoload.php';
$gitkitClient = Gitkit_Client::createFromFile(dirname(__FILE__) . '/identity-toolkit-php-master/gitkit-server-config.json');
$gitkitUser = $gitkitClient->getUserInRequest();
?>
<!-- End modification 1 -->
<!-- 1: Configure the sign-in button -->
<script type="text/javascript" src="//www.gstatic.com/authtoolkit/js/gitkit.js"></script>
<link type=text/css rel=stylesheet href="//www.gstatic.com/authtoolkit/css/gitkit.css" />
<script type=text/javascript>
window.google.identitytoolkit.signInButton(
'#navbar', // accepts any CSS selector
{
widgetUrl: "/gitkit.php",
signOutUrl: "/index.php",
cookiePolicy: "single_host_origin",
}
);
</script>
<!-- End modification 1 -->
</head>
<body>
<!-- 2: Include the sign in button widget with the matching 'navbar' id -->
<div id="navbar"></div>
<!-- End modification 2 -->
<!-- 2: Print the user information if a signed in user is present -->
<p>
<?php if ($gitkitUser) { ?>
Welcome back!<br><br>
Email: <?= $gitkitUser->getEmail() ?><br>
Id: <?= $gitkitUser->getUserId() ?><br>
Name: <?= $gitkitUser->getDisplayName() ?><br>
Identity provider: <?= $gitkitUser->getProviderId() ?><br>
<?php } else { ?>
You are not logged in yet.
<?php } ?>
</p>
<!-- End modification 2 -->
</body>
</html>
My gitkit.php page:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copy and paste here the "Widget javascript" you downloaded from Developer Console as gitkit-widget.html -->
<script type="text/javascript" src="//www.gstatic.com/authtoolkit/js/gitkit.js"></script>
<link type="text/css" rel="stylesheet" href="//www.gstatic.com/authtoolkit/css/gitkit.css" />
<script type="text/javascript">
var config = {
widgetUrl: 'http://briansfakedomainname.com',
signInSuccessUrl: '/log.php',
signOutUrl: '/index3.php',
oobActionUrl: '/email.php',
apiKey: 'AIzaSyCrPO3VTtkeBg5F3Ssx_IIQuVFgSm1GBHM',
siteName: 'this site',
signInOptions: ["password","google"]
};
// The HTTP POST body should be escaped by the server to prevent XSS
window.google.identitytoolkit.start(
'#gitkitWidgetDiv', // accepts any CSS selector
config,
'JAVASCRIPT_ESCAPED_POST_BODY');
</script>
<!-- End modification -->
</head>
<body>
<!-- Include the sign in page widget with the matching 'gitkitWidgetDiv' id -->
<div id="gitkitWidgetDiv"></div>
<!-- End identity toolkit widget -->
</body>
</html>