Reputation: 5722
In the Firebase unity3D SDK When I try to obtain the credential it ask me for an id_token and an access_token .
I have guess that access_token must be null for some examples I have seen, but I have no idea of what to do with this id_token. Code example:
This is the call:
Firebase.Auth.GoogleAuthProvider.GetCredential(string id_token,string access_token);
This is an unity3D example 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 the Oauth 2.0 token which comes from from the google console. But this seems to not be working . Google answer is telling me the next:
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 of what I'm doing wrong?
Upvotes: 6
Views: 4024
Reputation: 39
You need to use Google Sign in SDK for unity to sign in with google first, after singed, you will get id_token to auth with Firebase.
Upvotes: 1
Reputation: 2013
Yes, that is a Oauth 2.0 token that is required here,
for that you can use this.
n you can't provide your own token as it may change with respect to 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 */
}
Upvotes: 1
Reputation: 2485
The firebase sample for google sign in in unity should help you with this. One of the first steps mentions:
Follow instructions for Android and iOS to get an ID token for the Google sign in.
The firebase documentation also has a subsection for manually verifying id tokens but they do advice against this.
Upvotes: 1