Search code examples
firebasefirebase-authenticationgoogle-oauthgoogle-authenticationgoogle-api-client

How to get oauth token on reload firebase web app?


Ok, my english isn't too good, so I will try to be clearliest possible.

I have an app that use firebase authentication with GoogleAuthProvider

var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider);

It works fine, I got oauth token and works very good. the session keep alive for anytime wath I may need; recently, I decide implement an API that needs an oauth token and I don't have any problem. Then, the trouble, when I reload/close/reopen/oauth token life timesout, the page/app, I'm already logged in but don't have a valid oauth token.

Firebase authentication doesn't provide any method to refresh or get the token again(I'm not sure).

Have I to use any other API?


Solution

  • Firebase Auth doesn't provide a mechanism for refreshing OAuth credentials for Google or other social login providers. This is possible, however, using the Google Sign-In JS.

    You can use the Google Sign-In library to sign the user in and obtain OAuth tokens, and then use signInWithCredential() to authenticate with Firebase Auth.