我已按照快速入门指南在PHP中设置基本网站以使用Google Identity Toolkit。 index.php页面上的小部件显示'登录'按钮。按下后,我将进入gitkit.php页面并提示输入我的电子邮件地址。在这样做之后,我被带到谷歌网站输入我的密码。在我这样做之后,我重定向回到我的网站,但小部件仍然说“登录”#39;并且index.php页面无法识别我已登录。登录过程中不会显示任何错误消息。花了相当多的时间试图诊断但没有到达任何地方。希望有人能指出我正确的方向。
我已在我的计算机上设置了hosts文件,将briansfakedomainname.com指向我的LAN上可访问的网络服务器。
我的index.php页面:
<!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>
&#13;
我的gitkit.php页面:
<!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>
&#13;
答案 0 :(得分:0)
嘿Brian你是否在开发者控制台中设置了你的widget url gitkit.php?在您通过谷歌登录后,您应首先被重定向到完成登录过程的小部件网址,然后在成功时重定向到登录成功网址。这无缝地发生。同时确保小部件和登录成功URL与您使用单个主机源cookie策略具有相同的域名。