Apple使用FireBase Auth登录android有问题

Posted

技术标签:

【中文标题】Apple使用FireBase Auth登录android有问题【英文标题】:Apple login in android with FireBase Auth has problem 【发布时间】:2021-03-15 05:50:34 【问题描述】:

Google 帐户的成绩是 spark。

Firebase 项目有两个平台,androidios

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

其次,我创建 Apple Service Id 并将域配置为 'fb-projectid.firebaseapp.com'

并将网址作为“https://fb-projectid.firebaseapp.com/__/auth/handler”副本从 Firebase 身份验证 - 登录方法 - 苹果返回。

第三,使用 Grouped App Id 制作 Apple 私钥。

四、复制Key ID + Key文件内容并粘贴到Firebase Authentication - Sign-in Method - apple - OAuth 代码流配置。

在安卓应用中,我设置了按钮的 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 ]

我该如何解决这个问题?

【问题讨论】:

【参考方案1】:

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

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

【讨论】:

谢谢。在项目中,我们决定不添加该功能,hhhhh

以上是关于Apple使用FireBase Auth登录android有问题的主要内容,如果未能解决你的问题,请参考以下文章

多租户的 Firebase 身份验证和 Apple 登录

带有苹果登录的 Firebase 身份验证网络

在 iOS 13 上的 Swift 中使用 Apple for Firebase 设置登录时出错的原因是啥?

Android Sign in with apple and firebase flutter

Flutter Firebase Google Apple Facebook 登录

在 iOS 中使用 LinkedIn + firebase auth + Flutter 登录