Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Firebase signin giving status 12501 (not working), in release build variant and jks SHA

I know this question has been asked by many and have been answered.

So, why am I asking this question again? Cuz I tried those solutions, and I did followed Google docs, followed tutorials and youtube. Still no luck.

Oright, this is what I did in my project.

Project: GoogleSignIn

dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'com.google.gms:google-services:3.0.0'
      }

Gradle (Module: app)

apply plugin: 'com.android.application'

android {
    signingConfigs {
        config {
            keyAlias 'alias'
            keyPassword 'keypass'
            storeFile file('/home/reoxey/path/to/jks')
            storePassword 'storepass'
        }
    }
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "reoxey.com.googlesignin"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            signingConfig signingConfigs.config
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:design:25.0.0'
    compile 'com.google.firebase:firebase-auth:9.8.0'
    compile 'com.google.android.gms:play-services-auth:9.8.0'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

LoginActivity.java

gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.web_client_key))
                .requestEmail()
                .build();

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();

        findViewById(R.id.sign_in_button).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
                startActivityForResult(signInIntent, RC_SIGN_IN);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RC_SIGN_IN){
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            if (result.isSuccess()){
                Toast.makeText(getApplicationContext(),"Nailed it",Toast.LENGTH_LONG).show();
            }else {
                Snackbar.make(mLoginFormView,result.getStatus().toString(),Snackbar.LENGTH_LONG).show();
                Toast.makeText(getApplicationContext(),"Messed",Toast.LENGTH_LONG).show();

            }
        }
    }

string.xml

<string name="web_client_key">123456789-clientwebapplication.apps.googleusercontent.com</string>

There is no special configuration in manifest, and I believe that I am not missing anything there.

google-services.json

{
  "project_info": {
    "project_number": "{numeric-id}",
    "firebase_url": "https://project--123456789.firebaseio.com",
    "project_id": "project--123456789",
    "storage_bucket": "project--123456789.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:{numeric-id}:android:sfdjgsdkdfgsfs",
        "android_client_info": {
          "package_name": "reoxey.com.googlesignin"
        }
      },
      "oauth_client": [
        {
          "client_id": "{numeric-id}-androidkey.apps.googleusercontent.com",
          "client_type": 1,
          "android_info": {
            "package_name": "reoxey.com.googlesignin",
            "certificate_hash": "{sha1-from-jks-file}"
          }
        },
        {
          "client_id": "{numeric-id}-webapplication.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "{android-key}"
        }
      ],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "appinvite_service": {
          "status": 2,
          "other_platform_oauth_client": [
            {
              "client_id": "{numeric-id}-webapplication.apps.googleusercontent.com",
              "client_type": 3
            }
          ]
        },
        "ads_service": {
          "status": 2
        }
      }
    }
  ],
  "configuration_version": "1"
}

Oright, now Firebase console.

  • created project with package name
  • added sha1 fingerprint generated from jks file
  • enabled authentication for google signin

that's it I guess, hope I provided everything,
so what am I missing here.

When I click on google sign, it gives me an error with 12501 status code. I don't know what's wrong here. Anyone?

Thanks in Advance.

like image 663
reoxey Avatar asked Nov 12 '16 08:11

reoxey


1 Answers

When you build your GoogleSignInOptions, you use string resource web_client_key. For security reasons, you didn't post the real key and instead used example value 123456789-clientwebapplication.apps.googleusercontent.com..

That example value does not appear in the posted google-services.json, so I cannot match it with the values there. The value should be the client_id defined in this block:

{
  "client_id": "{numeric-id}-webapplication.apps.googleusercontent.com",
  "client_type": 3
}

Is that the value you used?

The conventional way of getting the web client ID is to use string resource R.string.default_web_client_id, which is generated by the Google Services Gradle Plugin from google-services.json. Is there a reason you cannot do that and must define your own string resource? Have you tried using default_web_client_id?

like image 130
Bob Snyder Avatar answered Sep 18 '22 16:09

Bob Snyder