简体   繁体   中英

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.

 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

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.

Oauth2 is authorization and returns an access token and refresh token granting your application access to a users data.

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. It's a separated JavaScript API, but packaged together with the authentication API.

Solution to your issue is to use Google Identity Services authorization API instead of signin to authorize a user using 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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