Getting new access token from refresh token

Skip to first unread message

Adam Geisen

Sep 8, 2023, 5:09:32 PM9/8/23
to Firebase Google Group
I'm trying to use google-auth-library to get a new access token for a user who authenticated using Google via Firebase in one of my React projects. I am saving the access token and refresh token when they sign in, and it works to access Google APIs within the first hour, but I cannot figure out how to get a new access token if it's expired (after that hour). 

I'm using Cloud Functions to make the calls, and I'm trying to get that new access token at the beginning of every Google API call.

I've been researching and trying new things for the last month and I can't get anything to give me a new valid access token. If you want me to post some code, I can. If you have any suggestions for some docs, that would be great. I feel like I've exhausted Stack Overflow and the Google API docs, but I very well could have missed something. Any ideas would be very much appreciated. Thanks!


Adam Geisen

Sep 13, 2023, 1:17:28 AM9/13/23
to Firebase Google Group
I'm going to answer my own question here, in case anyone was also wondering. 

This article pretty much solved the issue for me. Following her guide, I rebuilt my sign in screen and am no longer using the built-in signInWithGoogle functions. She also includes an axios call at the end in order to get a new access token from a saved refresh token. I don't know why, but I couldn't get anything else to work to refresh the token. This was the only thing that worked for me. Saved me a ton of time and frustration.

I also tried using blocking functions to save the refresh token when a person signs in for the first time, and that worked to save the access token and the refresh token. But I couldn't ever get the refresh token to give me a new access token after it expires. I didn't try it with the axios call in the above article, so it might have done the trick if you don't want to go away from the built in sign in functions.
Reply all
Reply to author
0 new messages