且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自动“继续为"文档谷歌弹出

更新时间:2023-10-02 23:30:58

编辑(2020年10月29日):

第一个链接现在再次起作用(如 @ManSamVampire 所指出的那样):

The first link is now working again (as pointed out by @ManSamVampire):

https://developers.google.com/identity/one-tap/web

编辑(2019年11月9日):

似乎这些链接现在指向404.我找不到有关One Tap登录消失的任何信息.

It seems the links now lead to 404s. I can't find any information about the disappearance of One Tap sign-in.

原始答案:

我有相同的问题并找到了这个问题(我用Google搜索"google自动登录"):

I had the same question and found this (I Googled "google automatic login"):

https://developers.google.com/identity/one-tap/网络/

它们的屏幕快照是用于移动设备的,但弹出窗口看起来与您在其他Web应用程序上看到的完全相同.

The screenshots they have are for mobile, but the popup looks exactly the same as the one you see on other web apps.

如果您点击指南标签,则应该在其中找到一些文档,其中包括入门部分:

If you click on the Guides tab, you should find some docs there including a Getting Started section:

https://developers.google.com/identity/one -tap/web/入门

这将向您展示如何像设置其他Google API(例如 Maps JavaScript API )一样获得凭据设置.

That will show you how to get the credentials setup just like you would for any other Google API, like the Maps JavaScript API for example.

获得凭据后,就可以从Google的主HTML文件中或任何其他加载脚本的位置加载库,如果有的话:

Once you have your credentials, you load the library from Google in your main HTML file or wherever you load your other scripts, if you have any:

<script src="https://smartlock.google.com/client"></script>

然后,您应该可以通过 googleyolo 对象访问该库:

You should then be able to access the library through the googleyolo Object:

window.onGoogleYoloLoad = (googleyolo) => {
  // The 'googleyolo' object is ready for use.
};

您在该屏幕截图中看到的(以及我也看到的)看起来像是googleyolo.hint()呼叫.

What you are seeing in that screenshot (and what I have seen as well) looks to be a googleyolo.hint() call.

这似乎取决于用户是否已经登录该网站.如果他们已经或在浏览器中保存了该网站的密码,则它应该自动登录或至少提示输入密码.除了使用前面提到的googleyolo.hint()调用的登录之外,该API还可以处理注册.

It seems to be dependent on whether the user has already logged into the site or not. If they have or if they have a password saved for the site in their browser, then it should automatically sign them in or at least prompt for it. This API also handles sign-up's in addition to sign-in's which uses the googleyolo.hint() call mentioned before.

更多详细的代码示例可在指南页面上找到.

More detailed code examples can be found on the Guides page.

您还需要控制此站点的后端,以通过成功的googleyolo.hint()googleyolo.retrieve()调用来验证 ID令牌的完整性.有关内容,请参见 https://developers.google.com/identity/一键式/web/idtoken-auth .

You will also need control over the backend for this site to verify the integrity of the ID tokens from a successful googleyolo.hint() or googleyolo.retrieve() call. That is covered at https://developers.google.com/identity/one-tap/web/idtoken-auth.