FirebaseUI-iOS icon indicating copy to clipboard operation
FirebaseUI-iOS copied to clipboard

FirebaseAuthUI not creating new user from Facebook authentication - Swift

Open heydana opened this issue 10 years ago • 25 comments

After setting up FirebaseAuthUI for Facebook - adding the redirect URIs to my Facebook app login details, facebook app ID to the Info.plist - I'm able to get my simple test app to go through all the steps to authenticate Facebook, but upon completion no new user is created in the authentication database. The app will show up under permissions in my Facebook account, but no new user is created in Firebase.

Google authentication and email/password authentication work as expected and correctly create a new user.

This is the function I use for my simple sign-in button:

@IBAction func signIn() {

    let authUI = FIRAuthUI.authUI()!
    let googleAuthUI = FIRGoogleAuthUI.init(clientID:FIRApp.defaultApp()!.options.clientID)
    let facebookAuthUI = FIRFacebookAuthUI.init(appID: NSBundle.mainBundle().infoDictionary?["FacebookAppID"] as! String)  
    authUI.signInProviders = [googleAuthUI!, facebookAuthUI!]       

    let authViewController = FIRAuthUI.authUI()!.authViewController()        
    self.presentViewController(authViewController, animated: true, completion: nil)

}

(cross posted on: http://stackoverflow.com/questions/38317938/firebaseauthui-not-adding-new-facebook-user)

heydana avatar Jul 12 '16 04:07 heydana

Are you getting any errors in the process? Can you check FIRAuth.auth()?.currentUser and see if there's a signed in user?

asciimike avatar Jul 12 '16 09:07 asciimike

So I added FIRAuth.auth()?.addAuthStateDidChangeListener and I got it to fire with Google and email login, but not Facebook...

heydana avatar Jul 12 '16 21:07 heydana

Just a quick check, have you enabled Facebook on Firebase console?

ch40w31 avatar Jul 12 '16 23:07 ch40w31

Yup it's enabled. screen shot 2016-07-12 at 4 04 54 pm

heydana avatar Jul 12 '16 23:07 heydana

Thanks! Can you please do the following to help debug the issue?

  • Make a temporary variable of the handleOpenURL result and place a breakpoint there.
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    let handled = FIRAuthUI.authUI()!.handleOpenURL(url, sourceApplication: sourceApplication!)
    return handled
}
  • Start and finish a Facebook sign-in flow and you should hit the breakpoint.

If handled is false, most likely there's something wrong with the Facebook setup. Check your plist file against the "Configure Xcode Project" section of this doc, make sure there's a CFBundleURLSchemes value for Facebook in particular.

ch40w31 avatar Jul 12 '16 23:07 ch40w31

Put in the breakpoint and handled is true.

heydana avatar Jul 13 '16 00:07 heydana

Hmm, are you getting any callback in func authUI(authUI: FIRAuthUI!, didSignInWithUser user: FIRUser?, error: NSError?)? Is the auth view controller dismissed after you sign in with Facebook?

ch40w31 avatar Jul 13 '16 00:07 ch40w31

Yes, the view controller is dismissed after signing in with Facebook and the app is shown as authorized in my facebook profile settings (for "Logged in using Facebook"). However, I'm not getting any callbacks for any of the sign-ins using the didSignInWithUser method. I do get a call with the FIRAuth.auth().addAuthStateDidChangeListener for Google and email/password (but not facebook).

heydana avatar Jul 13 '16 00:07 heydana

Did you set the delegate of FIRAuthUI to the object that implements didSignInUser?

ch40w31 avatar Jul 13 '16 16:07 ch40w31

Oops, thanks. Ok with delegate assigned, I'm getting a callback for all three providers, but still no Facebook account creation.

heydana avatar Jul 13 '16 23:07 heydana

Do you happen to use Facebook and Google accounts with the same email address? In this case, the two providers are linked to the same Firebase account.

ch40w31 avatar Jul 13 '16 23:07 ch40w31

Yes, however even without my Google account saved (I've tried deleting the account to have zero accounts at all in the database), the Facebook authentication still doesn't create a new user.

heydana avatar Jul 13 '16 23:07 heydana

Also forgot to mention with didSignInUser, the user is nil when trying facebook login, but is assigned for Google/email.

heydana avatar Jul 13 '16 23:07 heydana

Aha! Got the full error details - still not sure what the issue is as I've provided my app secret to Firebase? FIRAuthErrorUserInfoDeserializedResponse - "Unsuccessful debug_token response from Facebook: {"error":{"message":"(#100) You must provide an app access token or a user access token that is an owner or developer of the app","type":"OAuthException","code":100,"fbtrace_id":"ByZKant9ike"}}"

heydana avatar Jul 13 '16 23:07 heydana

Oh, I found the issue!

In my advanced settings within the facebook app, I had turned on "Is App Secret embedded in the client?"

Turning that off made it all work! screen shot 2016-07-13 at 5 19 50 pm

heydana avatar Jul 14 '16 00:07 heydana

@heydana Sory i cannot find is app secret embedded in the client? where i can find?

ryanzulham avatar Jan 25 '17 06:01 ryanzulham

@ryanzulham facebook app portal -> Settings -> Advanced (top most section right side slider) screen shot 2017-02-08 at 10 46 33 pm

hvkale avatar Feb 09 '17 04:02 hvkale

@ObamaBinLaden1 I still see it, not sure what's different

hvkale avatar Jul 21 '17 18:07 hvkale

@heydana I disabled "Is App Secret embedded in the client". Still getting the same error.

iballan avatar Jul 25 '17 07:07 iballan

Still not creating new user ?

dkdilipkumar avatar Aug 25 '17 10:08 dkdilipkumar