Google登录网站

时间:2018-07-17 10:50:39

标签: google-signin googlesigninapi

我遵循Google Sign-in for Websites并为登录和退出创建了以下页面。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="google-signin-client_id" content="00000000000-MY CLIENT ID">
<title></title>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script type="text/javascript">
    function signOut() {
        var auth2 = gapi.auth2.getAuthInstance();
        auth2.signOut().then(function () {
            console.log('User signed out.');
        });
    }
    function onSignIn(googleUser) {
        var profile = googleUser.getBasicProfile();
        console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
        console.log('Name: ' + profile.getName());
        console.log('Image URL: ' + profile.getImageUrl());
        console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
    }
</script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn"></div>

<a href="#" onclick="signOut();">Sign out</a>

<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

我对这个样本有一些疑问。

  1. 使用Internet Explorer,第一次登录和注销成功,第二次单击“登录IE”将打开一个新页面,并立即要求我允许关闭该页面。 enter image description here

  2. 使用Chrome浏览器,第一次登录和注销成功,第二次登录会自动登录,而无需我重新输入密码

0 个答案:

没有答案