简体   繁体   中英

iOS: Firebase and facebook account kit login

I wanted to ask if anyone could direct me to an example or explanation of how can I add a phone login for firebase using Facebook's Account Kit.

I am getting accessToken from facebook account kit and then try to authorize like this

fileprivate func authorizeWithAccessToken(_ accessToken: AKFAccessToken?, phoneNumber: AKFPhoneNumber?, error: NSError?) {
    guard let accessToken = accessToken else {
        return
    }

    FIRAuth.auth()?.signIn(withCustomToken: accessToken.tokenString) { (user, error) in
        if (error != nil) {
            print(error?.localizedDescription)
        } else {
            print("User logged in")
        }
    }
}

But I am getting error:

"The custom token format is incorrect. Please check the documentation." UserInfo={NSLocalizedDescription=The custom token format is incorrect. Please check the documentation., error_name=ERROR_INVALID_CUSTOM_TOKEN})

Here my token:

EMAWeGCejpgSijO0ncgBYl7HxLTZBy0rWrwaHihA81ZB286EEPhdZCtDSWZAnajp8pmX10E1ZCJDV7Ghwz0NrxRMhZCgSPzZC9imjbamk8bvv2AZDZD

Why are you using customTokens for Facebook authentication instead of using the built-in credentials methods Firebase has for Facebook?

Instead of the Token create a credentials object with the Facebook library:

let credential = FIRFacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)

and pass this object to the signIn(with: ) method.

FIRAuth.auth()?.signIn(with: credential) { (user, error) in
    if let err = error {
      print(err?.localizedDescription)
     return
   }

   // Do your stuff here....
}

A full documentation of using Firebase and Facebook can be found here

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