简体   繁体   中英

Apple login in android with FireBase Auth has problem

Google account's grade is spark.

Firebase project has two platforms, android and ios.

First, download google-services.json and move to /app.

Second, I create Apple Service Id and configure domains as ' fb-projectid .firebaseapp.com'

and return urls as 'https:// fb-projectid .firebaseapp.com/__/auth/handler' copy from Firebase Authentication - Sign-in Method - apple.

Third, make Apple Private Key with Grouped App Id.

Fourth, copy Key ID + Key file content and paste to Firebase Authentication - Sign-in Method - apple - OAuth code flow configuration.

In android app, I set button's 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)
                }
    }
}

But I got an error

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 ]

How can I solve this problem?

You need to add your SHA-1 key to the Firebase project.

Open your app in Firebase-> Settings -> General -> SDK setup and configuration -> Add fingerprint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM