1

We are using Firebase with VueJS to manage sign-in to our application. And we also need to access other Google APIs using the accessToken, unfortunatly, the token expire after one hour.

    import firebase from 'firebase'

    firebase.auth().signInWithPopup(provider)
      .then(firebaseUser => {

        var accessToken = firebaseUser.credential.accessToken;
      })

How can we renew periodicaly the accessToken in order to keep accessing other google API without having to sign-out and sign-in from Firebase ?

I've done some research and i did not find any suitable, simple solution to this issue.

Similar questions

Edit This question is related to the refresh of accessToken not IdToken

firebaseUser.credential: 
   accessToken: "ya29.GlwyBic64v6PW8......"
   idToken: "eyJhbGciOiJSUzI1NiIsImt...."
   providerId: "google.com"
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • 2
    The accepted answer in that question can be applied to yours. Have you tried that? – dvnguyen Oct 10 '18 at 02:16
  • 1) I do not think that waiting for the token to generate auth error is the best case senario, i am looking for a better approach to this problem (2) My question still persist, how can we renew the `accessToken` without having to log-out and log in ? – username_not_found Oct 10 '18 at 02:23
  • 1
    Maybe you should be using the Google auth APIs directly rather than relying on Firebase. https://developers.google.com/identity/protocols/OAuth2UserAgent – Doug Stevenson Oct 10 '18 at 02:57
  • @DougStevenson Yes, that a possibility, Can you provide more details ? Will the Google Auth API maintain the valid state of the `accessToken`/`refreshToken` ? It seems there is a way to [inject](https://github.com/google/google-api-javascript-client/issues/304#issuecomment-307655705) `accessToken`, but how do we retreive the **current** token afterward to persist it between page views ? I need help figuring out the full workflow, and this seems like a question everybody will face. – username_not_found Oct 10 '18 at 03:29
  • Sorry, I don't know. This is definitely not a question "everybody will face". – Doug Stevenson Oct 10 '18 at 03:59

0 Answers0