How to initialize firebase after android google login?

Noman :

I wanted to try and keep my native android firebase development to minimum so as to when I'm ready to port to IOS/web I won't be doing a lot there.

Right now firebase's Javascript doesn't allow google login from Android, this can be taken care of from the plugin. But what I'm stuck on is how to initialize firebase based on the Java Android Google login.

So this is what I'm trying to achieve:

Cordova calls Java-Android-Native login into google ---> based on this, how would I initialize firebase?

This plugin can let me login into google natively: https://www.npmjs.com/package/cordova-plugin-googleplus

But I guess I need auth token? token ID?

firebase.auth().signInWithCredential(credential).catch(function(error) {
  } else {
    console.error(error);
  }
 });

Can this give me the above required toke? https://developers.google.com/identity/sign-in/android/sign-in

GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);

Update 1: Just want to share more information. When getting the user logged in through google on android I have the below object

GoogleSignInAccount

https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInAccount

It has public String getIdToken () & public String getServerAuthCode () why can't these be used to authenticate firebase using JS?

Update 2: Answer provided by Faraz seems to be working. Here is reference for the function signInWithCredential https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithCredential

Thank you for your help.

Faraz :

Use auth.signInWithCredential with the GoogleAuthProvider credential.

Here is an example:

auth.signInWithCredential(firebase.auth.GoogleAuthProvider.credential(googleAccessToken)).then(function(user) {
  // Google User is logged in
}).catch(function(error) {
  // Error
});

Source for more infomation

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=450131&siteId=1