Micah Simmons Micah Simmons - 1 year ago 151
Java Question

"FirebaseError: Invalid authentication credentials provided" error when setting up google sign in on Android

I've been trying to set up a google login for my app.

I followed the tutorial here:


I did everything. I can sign in sign in and sign out.

Then I added an Async task to get a token, which it seems to successfully retrieve. It is implemented as follows:

private class GetIdTokenTask extends AsyncTask<Void, Void, String> {

private static final String SERVER_CLIEdNT_ID = "749433126040-ca4gfj7ucuh0m2suo3230u03o3d7doni.apps.googleusercontent.com";

protected String doInBackground(Void... params) {

String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
String scopes = "audience:server:client_id:" + SERVER_CLIEdNT_ID; // Not the app's client ID.
try {
return GoogleAuthUtil.getToken(getApplicationContext(), account, scopes);
} catch (IOException e) {
Log.e(TAG, "Error retrieving ID token.", e);
return null;
} catch (GoogleAuthException e) {
Log.e(TAG, "Error retrieving ID token. Google exception", e);
return null;

protected void onPostExecute(String result) {
Log.i(TAG, "ID token: " + result);
if (result != null) {

idToken = result;

Toast.makeText(context, "token is " + result, Toast.LENGTH_LONG).show();

} else {
// There was some error getting the ID Token
// ...
Toast.makeText(context, "token is null", Toast.LENGTH_LONG).show();


So after running the method and getting the token, I then run the generic firebase code to connect to Firebase (having already set up a google app, put the client ID in firebase, enabled it etc.) I got the code from https://www.firebase.com/docs/android/guide/login/google.html

And implemented it as follows:

public void loginFireBase() {

Firebase ref = new Firebase("https://boiling-fire-944.firebaseio.com");
ref.authWithOAuthToken("google", idToken, new Firebase.AuthResultHandler() {

public void onAuthenticated(AuthData authData) {
// the Google user is now authenticated with your Firebase app

Toast.makeText(context, "user succesfully authenticated with firebase", Toast.LENGTH_LONG).show();
Toast.makeText(context, idToken, Toast.LENGTH_LONG).show();

public void onAuthenticationError(FirebaseError firebaseError) {

Log.v("firebase problem", firebaseError.toString());
Toast.makeText(context, "I'm an authenticated error" + "id Token was " + idToken, Toast.LENGTH_LONG).show();



So ultimately, I login, I get a token, and then pass it to the firebase authWithOAuthToken method, and then I get the error:

FirebaseError: Invalid authentication credentials provided.

Can anyone see any problems in my code? I have a feeling the token is not valid but can't find a way to check its validity.

Tell me if you need me to post more, I was trying to keep it brief.

Thanks to anybody who can help !

Answer Source

Whenever I need to authenticate with Firebase on Android, I go back to the Firebase Android login demo. Here's how that app gets the OAuth token for Google authentication:

String scope = String.format("oauth2:%s", Scopes.PLUS_LOGIN);
token = GoogleAuthUtil.getToken(

It looks like you're getting the cross-client id for the user, which is not a valid OAuth token.

Update (20160308): nowadays I instead look at the FirebaseUI library, which includes this functionality and is more up to date.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download