LoginSignup
3
3

More than 3 years have passed since last update.

AndroidでFirebaseを使ったログインの際にINVALID_CERT_HASHが起きる場合の対処法

Posted at

Google Playアプリ署名が有効になっていると、自分のアプリ署名が削除され、アプリリリース後にGoogle Playが付与したアプリ署名が使われる。

スクリーンショット 2020-02-11 19.14.48.png

そのため、Firebaseログインを利用する場合、自分が署名した際のSHA-1フィンガープリントではなく、Google Playが署名した際のSHA-1フィンガープリントをFirebaseの設定で登録する必要がある。

スクリーンショット 2020-02-11 19.12.54.png

上記の手順を行っていない場合、Firebaseを使ったログインの際、下記のコードで例外が起きる。

firebaseAuth
        .startActivityForSignInWithProvider(MainActivity.this, provider.build())
        .addOnSuccessListener(
                new OnSuccessListener<AuthResult>() {
                    @Override
                    public void onSuccess(AuthResult authResult) {
                    }
                })
        .addOnFailureListener(
                new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        // ここで例外が起きる
                        e.printStackTrace();
                    }
                });


エラーメッセージに書かれているINVALID_CERT_HASHは、Play Storeが施したアプリ署名のSHA-1フィンガープリントとFirebaseに登録されたSHA-1フィンガープリントが一致しない場合に起きる。

E/FirebaseAuth: [GetAuthDomainTask] Error getting project config. Failed with INVALID_CERT_HASH 400
E/IdpSignInActivity: Web sign-in failed, finishing

スタックトレースの直前に書かれているThere was an error while trying to get your package certificate hashは「パッケージの証明書の署名が間違っているとき」に起きるエラーで、INVALID_CERT_HASHと同じ意味になる。

com.google.firebase.auth.FirebaseAuthException: There was an error while trying to get your package certificate hash.
    at com.google.firebase.auth.api.internal.zzdv.zza(com.google.firebase:firebase-auth@@19.2.0:37)
    at com.google.firebase.auth.internal.zzal.onReceive(com.google.firebase:firebase-auth@@19.2.0:32)
    at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)
    at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

参考リンク

下記のリンクにはもう少し詳しい説明が書いてある。

Authorization issue with Firebase when publish app to Play Store

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3