Firebase: authentication using google, where should I get id_token?

in the Firebase3D sole purpose SDK When I try to get the credentials, ask me for id_token and access_token .

I assume that access_token should be null for some examples I saw, but I have no idea what to do with this id_token. Code example:

It's a challenge:

Firebase.Auth.GoogleAuthProvider.GetCredential(string id_token,string access_token); 

This is a sample unit3D code:

 public void GoogleLogin(Action<bool> loginOK) { string id_token = "90096201****-353hvgf63fecvvc3mi****s6140f98a.apps.googleusercontent.com"; Firebase.Auth.Credential credential; credential = Firebase.Auth.GoogleAuthProvider.GetCredential(id_token,null); auth.SignInWithCredentialAsync(credential).ContinueWith (task => { if (!task.IsCanceled && !task.IsFaulted) { loginOK(true); } else { loginOK(false); } if (task.Exception != null) { Debug.LogException(task.Exception); } }); } 

I thought it would be an Oauth 2.0 token that comes from the Google console. But this does not seem to work. Google answer tells me the following:

11-29 13: 58: 25.476 com.google.android.gms 2009 3225 i AuthChimeraService
"message": " Unable to parse Google id_token : 90096201 **** - **** 353hvgf63fecvvc3mi s6140f98a.apps.googleusercontent.com"

Any idea what I'm doing wrong?

+5
source share
3 answers

a sample google login database of unity should help you with that. One of the first steps:

Follow the instructions from Android and iOS to get your Google login ID.

The firebase documentation also has a manual id token validation unit, but they advise against this.

+1
source

Yes, this is the Oauth 2.0 token that is required here,

you can use this for this.

n you cannot provide your own token, as it may change in relation to the user.

 private void getGoogleOAuthTokenAndLogin() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); // Log.e("SahajLOG", "Login PREF ISSSSSSSS ONCREATE "+prefs.getBoolean("AuthByGplus", AuthByGplus)); if (!prefs.getBoolean("AuthByGplus", AuthByGplus)) { AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() { String errorMessage = null; @Override protected String doInBackground(Void... params) { String token = null; try { String scope = String.format("oauth2:%s", Scopes.PLUS_LOGIN); token = GoogleAuthUtil.getToken(MainActivity.this, Plus.AccountApi.getAccountName(mGoogleApiClient), scope); } catch (IOException transientEx) { /* Network or server error */ Log.e("SahajLOG", "Error authenticating with Google: " + transientEx); errorMessage = "Network error: " + transientEx.getMessage(); } catch (UserRecoverableAuthException e) { Log.w("SahajLOG", "Recoverable Google OAuth error: " + e.toString()); /* We probably need to ask for permissions, so start the intent if there is none pending */ if (!mIntentInProgress) { mIntentInProgress = true; Intent recover = e.getIntent(); startActivityForResult(recover, MainActivity.GOOGLE_SIGIN); } } catch (GoogleAuthException authEx) { /* The call is not ever expected to succeed assuming you have already verified that * Google Play services is installed. */ Log.e("SahajLOG", "Error authenticating with Google: " + authEx.getMessage(), authEx); errorMessage = "Error authenticating with Google: " + authEx.getMessage(); } return token; } @Override protected void onPostExecute(String token) { mGoogleLoginClicked = false; Intent resultIntent = new Intent(); if (token != null) { Log.e("SahajLOG", "TOKEN IS " + token); // firebaseAuthWithGoogle(token); //onGoogleLoginWithToken(token); resultIntent.putExtra("oauth_token", token); } else if (errorMessage != null) { resultIntent.putExtra("error", errorMessage); } setResult(MainActivity.GOOGLE_SIGIN, resultIntent); finish(); } }; task.execute(); } Log.e("SahajLOG", "oAuthCalled"); /* Get OAuth token in Background */ } 
+1
source

You need to use the Google Sign in SDK for unity to enter Google first, after you sing, you will get id_token for authorization with Firebase.

+1
source

Source: https://habr.com/ru/post/1260524/


All Articles