简体   繁体   English

如何获取“使用 Google 登录”的刷新令牌

[英]How to get refresh token for "Sign In With Google"

I have been trying to create a refresh token since the access token keep on expiring in 1hr.我一直在尝试创建刷新令牌,因为访问令牌会在 1 小时后过期。

 window.onload = function () {
    google.accounts.id.initialize({
      client_id: ,
      callback: handleCredentialResponse,
    });

    google.accounts.id.renderButton(
      document.getElementById("google-signin-button"),
      { theme: "outline", size: "large", shape: "circle" } // customization attributes
    );
    google.accounts.id.prompt(); // also display the One Tap dialog
  };

In this doc from google nothing is mentioned about create a refresh token.在这个来自谷歌的文档中,没有提到创建刷新令牌。 https://developers.google.com/identity/gsi/web/guides/overview https://developers.google.com/identity/gsi/web/guides/overview

Anyone help me out thanks.任何人都可以帮助我谢谢。

Sign-in or authentication is login and returns and id token and an access token, and identifies the user behind the machine. Sign-in或身份验证是登录并返回 ID 令牌和访问令牌,并识别机器背后的用户。

Oauth2 is authorization and returns an access token and refresh token granting your application access to a users data. Oauth2是授权并返回访问令牌和刷新令牌,授予您的应用程序访问用户数据的权限。

Signin will not return a refresh token.登录不会返回刷新令牌。

If you read further on the page you linked you will fined a section intitled Separated Authentication and Authorization Moments如果您在链接的页面上进一步阅读,您将罚款标题为“ 分离的身份验证和授权时刻”的部分

To obtain an access token for use with Google APIs, or to load some user data, you need to call the Google Identity Services authorization API instead.要获取用于 Google API 的访问令牌,或加载一些用户数据,您需要调用Google 身份服务授权 API It's a separated JavaScript API, but packaged together with the authentication API.它是一个单独的JavaScript API,但与身份验证API打包在一起。

Solution to your issue is to use Google Identity Services authorization API instead of signin to authorize a user using Oauth2.您的问题的解决方案是使用Google 身份服务授权 API而不是登录来授权使用 Oauth2 的用户。

You were not following the good tutorial it took me time too to find it你没有遵循很好的教程我也花了时间才找到它

if you want a refresh token you need to use the server side way.如果你想要一个刷新令牌,你需要使用服务器端的方式。

https://developers.google.com/identity/protocols/oauth2/web-server#node.js https://developers.google.com/identity/protocols/oauth2/web-server#node.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM