使用 FireBase Auth 在 android 中的 Apple 登录有问题

Apple login in android with FireBase Auth has problem

Google 账号等级为spark.

Firebase 项目有两个平台,android 和 ios。

首先,下载google-services.json并移动到/app.

其次,我创建 Apple 服务 ID 并将域配置为“fb-projectid.firebaseapp.com”

和 return 网址作为 'https://fb-projectid.firebaseapp.com/__/auth/handler' 从 Firebase 身份验证复制 - 登录方法 - 苹果。

三、用Grouped App Id制作苹果私钥

四、复制Key ID+Key文件内容,粘贴到Firebase认证-登录方式-apple-OAuth码流配置

在 android 应用中,我设置了按钮的 setOnClickListener()

fun appleLogin(activity : FragmentActivity) {
    val provider = OAuthProvider.newBuilder("apple.com")
    provider.scopes = arrayOf("email", "name").toMutableList()
    provider.addCustomParameter("locale", "ko_KR")

    auth = Firebase.auth

    val pending = auth.pendingAuthResult
    if (pending != null) {
        pending.addOnSuccessListener { authResult ->
            Log.d(MyApp.tag, "checkPending:onSuccess:$authResult")
            // Get the user profile with authResult.getUser() and
            // authResult.getAdditionalUserInfo(), and the ID
            // token from Apple with authResult.getCredential().
        }.addOnFailureListener { e ->
            Log.w(MyApp.tag, "checkPending:onFailure", e)
        }
    } else {
        Log.d(MyApp.tag, "pending: null")
        auth.startActivityForSignInWithProvider(activity, provider.build())
                .addOnSuccessListener { authResult ->
                    // Sign-in successful!
                    Log.d(MyApp.tag, "activitySignIn:onSuccess:${authResult.user}")
                    val user = authResult.user
                    // ...
                }
                .addOnFailureListener { e ->
                    Log.w(MyApp.tag, "activitySignIn:onFailure", e)
                }
    }
}

但是我得到一个错误

activitySignIn:onFailure com.google.firebase.auth.FirebaseAuthException: There was an error while trying to get your package certificate hash. [ Client does not match API key ]

我该如何解决这个问题?

您需要将 SHA-1 密钥添加到 Firebase 项目。

在 Firebase -> 设置 -> 常规 -> SDK 设置和配置 -> 添加指纹中打开你的应用程序。