how to get offline_token in firebase auth?

154 views
Skip to first unread message

Utkarsh Bhimte

unread,
May 2, 2020, 11:11:18 AM5/2/20
to Firebase Google Group
The requirement of the app is that I should be able to query data of a user's google calendar list and be able to notify him using a Cron job. 

If I use the additional scope on firebase auth, how can I use that token to query data from a firebase function, I am also curious about how the token refresh will work in this given situation?

Sam Stern

unread,
May 4, 2020, 9:01:36 AM5/4/20
to Firebase Google Group
Hi Utkarsh,

When you use Firebase Auth with Google Sign In we do a one time exchange to get the user's information.  Firebase does not keep the Google access/refresh/offline tokens and deal with them over time.  If your app needs offline access to the Google user's account you'll have to manage those tokens yourself.


- Sam

On Sat, May 2, 2020 at 11:11 AM Utkarsh Bhimte <workwit...@gmail.com> wrote:
The requirement of the app is that I should be able to query data of a user's google calendar list and be able to notify him using a Cron job. 

If I use the additional scope on firebase auth, how can I use that token to query data from a firebase function, I am also curious about how the token refresh will work in this given situation?

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/edfbe5f0-114d-4564-8afa-32a5a0df2f6c%40googlegroups.com.

Utkarsh Bhimte

unread,
May 5, 2020, 12:11:51 AM5/5/20
to fireba...@googlegroups.com
In that case, I think I'll have to use Google Oauth server-side and then link those credentials to Firebase auth, right? 

I am using firestore and I want the firestore db rules to work properly that is why I want to link the Google auth with Firebase.

Sam Stern

unread,
May 5, 2020, 8:16:49 AM5/5/20
to Firebase Google Group
Hi Utkarsh,

So you'll want to do a few things:
  1. Use Google Sign In client side to get an ID token as well as the tokens you need for offline access.
  2. Use the ID token client side to sign in with Firebase (signInWithCredential)
  3. Send the offline access tokens to your server to save them for future use.
Hope that helps,
Sam

Utkarsh Bhimte

unread,
May 5, 2020, 2:49:57 PM5/5/20
to fireba...@googlegroups.com
The tokens I am getting in the frontend auth, refresh token is not there. How should I handle token refreshes? 

Sam Stern

unread,
May 5, 2020, 3:14:35 PM5/5/20
to Firebase Google Group
Hi Utkarsh,

You need to send the server auth code you get from Google Sign In to your server where you can exchange it for a refresh token (if you have the right scopes, etc).  This really has nothing to do with Firebase Auth, it's something you'll have to do separately using the Google Sign In APIs.  If you're not sure how to do this I suggest asking on StackOverflow.

- Sam

Utkarsh Bhimte

unread,
May 5, 2020, 3:33:15 PM5/5/20
to fireba...@googlegroups.com
Thanks, Sam, I will look into it, truly appreciate your help. 😊

Reply all
Reply to author
Forward
0 new messages