Search code examples
javascripthtmlauthenticationgoogle-authenticationgoogle-oauth

Google Sign-in for websites - How to get token


I am using Google sign-in for Websites. https://developers.google.com/identity/sign-in/web/

Per documentation, under the function onSignIn(googleUser), I get an ID_Token using googleUser.getAuthResponse().id_token

But apparently this is not the access_token that I can use in future to revoke. How can I get the access_token on the client side from googleUser object?


Solution

  • Finally after several hours of breaking head, I got an answer from a Google developer.

    Use the following line. Passing true in getAuthResponse function returns the access_token and expiry. This is the recommended solution.

    googleUser.getAuthResponse(true).access_token;