Reputation: 581
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
Upvotes: 3
Views: 531
Reputation: 9346
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
Upvotes: 0