3

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

Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
Islam Temirbek
  • 571
  • 1
  • 5
  • 13

1 Answers1

0

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

pinedax
  • 9,246
  • 2
  • 23
  • 30
  • Thanks for your answer but I am not using Facebook I am using Facebook Account kit [link](https://developers.facebook.com/products/account-kit?&product_id=&gclid=Cj0KEQiA8orFBRCEpODivaOft_EBEiQAy3mlfXpghnE0rxDmWORuq87O-qTsXhjUdgzFHdxI5-WF_L0aArjK8P8HAQ) – Islam Temirbek Feb 14 '17 at 09:37