Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the refresh token with Google OAuth2 Javascript library?

Tags:

google-oauth

I'm using the Google OAuth2 Javascript library to request an access token from users. I want to store the token in a database on the server.

To be able to access that user's data after the token expiration, I also need to store the refresh token. I know how to do that when using a server-side Google OAuth2 library (specify access_type=offline), but I need to be able to do it with the client-side Javascript library and it doesn't work.

like image 903
cwarny Avatar asked Jan 13 '23 07:01

cwarny


1 Answers

You do not want to store the refresh token in the client! That would be akin to storing his username and password.

The Javascript client does not support type=offline, since that would expose the refresh token.

Your choices are :-

  1. Generate and store the refresh token on the server
  2. Have your client simply keep requesting access tokens as it needs them. Set immediate=true so there is no visible interaction with the user
like image 50
pinoyyid Avatar answered Jan 14 '23 21:01

pinoyyid