如何阻止Google+登录按钮弹出消息“欢迎回来,您已经通过Google+登录身份与该应用建立了联系...." [英] How to stop Google+ Sign-In Button from popping up the message "Welcome back, you've already connected with this app via Google+ Sign-In as ....."

查看:210
本文介绍了如何阻止Google+登录按钮弹出消息“欢迎回来,您已经通过Google+登录身份与该应用建立了联系...."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用向我的网站添加Google+登录按钮.服务器端流. 这是我呈现登录按钮的方式:

<script type="text/javascript">
    (function () {
        var po = document.createElement('script');
        po.type = 'text/javascript';
        po.async = true;
        po.src = 'https://plus.google.com/js/client:plusone.js?onload=renderGPlus';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(po, s);
    })();
</script>

<script type="text/javascript">
    function renderGPlus() {
        gapi.signin.render('customGPlusBtn', {
            'callback': 'gPlusSignInCallback',
            'clientid': '<my_client_id>',
            'redirecturi': 'postmessage',
            'accesstype': 'offline',
            'cookiepolicy': 'single_host_origin',
            'requestvisibleactions': 'http://schemas.google.com/BuyActivity',
            'scope': 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email'
        });
    }
</script>

加载按钮后,它将立即检查用户是否已授权我的应用程序(立即模式).如果用户以前已经授权了我的应用程序,则通知栏将在页面底部弹出,并显示消息欢迎回来,您已经通过Google+登录了此应用程序. /p>

是否有阻止该消息弹出的提示?

解决方案

首先,仅当用户针对特定浏览器会话进行Google识别的首次登录时,该消息才会出现.换句话说,只有关闭浏览器窗口并开始新的浏览器会话,用户才能看到该消息.

只要看到授权结果成功地将用户返回并更新到授权状态​​,就应该对用户进行授权.这样,只要出现此消息,用户就会自动登录.

由于显示的消息是用来通知您的用户他们已经自动登录,因此除非您有意为要明确管理其会话的用户故意这样做,否则您可能不应该禁止显示此消息.

但是,如果您实现了显式注销并正在管理用户的登录状态,则将以下代码更改为plusone.js同步包含将禁止该Toast消息.

<script src="https://apis.google.com/js/plusone.js">
  isSignedOut: true
</script>

另一个说明,您不再需要管理用户的状态来注销用户.新方法gapi.auth.signOut将使用户注销.您可以在此处查看退出演示.

如果您要进行异步包含,则以下全局配置标志将禁止显示该消息:

window.___gcfg = { isSignedOut: true };

更新:

Chimdi2000 指出,该解决方案在Chrome中不起作用.您可以添加以下CSS以隐藏生成的iframe:

iframe[src^="https://apis.google.com"] {
  display: none;
}

由于他的答案比我的答案要完整得多,并且还解决了其他问题,请检查一下.

I'm adding Google+ sign in button to my site using the server-side flow. Here is how I render the sign in button:

<script type="text/javascript">
    (function () {
        var po = document.createElement('script');
        po.type = 'text/javascript';
        po.async = true;
        po.src = 'https://plus.google.com/js/client:plusone.js?onload=renderGPlus';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(po, s);
    })();
</script>

<script type="text/javascript">
    function renderGPlus() {
        gapi.signin.render('customGPlusBtn', {
            'callback': 'gPlusSignInCallback',
            'clientid': '<my_client_id>',
            'redirecturi': 'postmessage',
            'accesstype': 'offline',
            'cookiepolicy': 'single_host_origin',
            'requestvisibleactions': 'http://schemas.google.com/BuyActivity',
            'scope': 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email'
        });
    }
</script>

When the button is loaded, it immediately checks to see if the user has authorized my application (immediate mode). If the user has previously authorized my application, a notification bar will pop up at the bottom of the page with the message "Welcome back, you've already connected with this app via Google+ Sign-In as .....".

Is there anyway to stop this message from popping up?

解决方案

First, the message only appears the first time that a user is signing in as recognized by Google for a particular browser session. In other words, the user will only see the message if they have closed their browser windows and have started a new browser session.

You should be authorizing the user any time that you are seeing the authorization result successfully returning and updating the user to an authorized state. As such, the user is getting automatically signed in whenever this message appears.

Because the message that appears is there to inform your users that they have automatically been signed in, you probably should not be suppressing this message unless you are doing it intentionally for a user whose session you are explicitly managing.

However, if you have implemented explicit sign-out and are managing the user's signed-in state, the following code change to the plusone.js synchronous include will suppress the toast message.

<script src="https://apis.google.com/js/plusone.js">
  isSignedOut: true
</script>

Another note, you no longer need to manage the user's state to sign the user out. The new method gapi.auth.signOut will sign the user out. You can see a demo of signout here.

If you are doing an asynchronous include, the following global configuration flags will suppress the message:

window.___gcfg = { isSignedOut: true };

UPDATE:

As pointed out by Chimdi2000 this solution does not work in Chrome. You can add the following CSS to hide the generated iframe:

iframe[src^="https://apis.google.com"] {
  display: none;
}

As his answer is far more complete than mine and addresses additional issues, please check it out.

这篇关于如何阻止Google+登录按钮弹出消息“欢迎回来,您已经通过Google+登录身份与该应用建立了联系...."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆