Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Parse Facebook Login error 308 FBSDKLoginBadChallengeString

I'm trying to implement Facebook login in my iOS app, using Parse.

let permissionsArray = ["public_profile", "email"]

PFFacebookUtils.logInInBackgroundWithReadPermissions(permissionsArray)
    { (user: PFUser?, error: NSError?) in

    if let user = user {
        //we logged in!
    }
    else {
        //login error!
    }
}

This works well in the Simulator, but not on the device. On the device, I get this error:

Error Domain=com.facebook.sdk.login Code=308 "The operation couldn’t be completed. (com.facebook.sdk.login error 308.)

Error code 308 is for FBSDKLoginBadChallengeString, "The login response was missing a valid challenge string."

After I authorise my app on Facebook, this gets called:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

The url is:

fb1640722449492705://authorize/#state=%7B%22challenge%22%3A%225OKWv3wN%2BEH%2BeQu48Xv6ty%2BRuek%3D%22%2C%22com.facebook.sdk_client_state%22%3Atrue%2C%223_method%22%3A1%2C%220_auth_logger_id%22%3A%22564CD915-2CFC-4989-9AF6-CEA389908D51%22%7D&granted_scopes=user_birthday%2Cpublic_profile&denied_scopes=&signed_request=c8SBBDeaNpF-R_XTYx4LRA0BWm5p9IwXDr8M4nL3YXI.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiJBUURhTXJibGw4Q3dITkd5M0xnQmNkVTNuYWRkeEVoTU5mMmx3eFpZU2IwZl9SU284YXhZdXZaRS02RnA2bU5Cdy1CWkVoRmt2Zk1xX1AxSHltUG00aWhkWE9hYmlvWFBiMnpCYkVnR1RRX3lzZVFIZXdHU19OcmpkNUF6WGtob1dfVE4wTmRrSGk5MzY0V2hFWUJDV0dfcE16RXpQVExHWE13X1dzb0QzZGtITm5fM0tHNjFxUjJyM3RDWVlNQTE4WENpS1dXTHUyM2dIRVhmTXc3ZTQ0M2xDQUtGRl9KSXcyVk1sS01FOTQ4dHQ2U1Fqb0tlVkp4RmJNSEFsWDZFYWxlUnQ2aGRrTGZlU2xuVTV5VjZ1bFhldHkxeEV5RmRDZVFHb2RXQ0dULVVCd3QyM0haY0dxNk8zbnE1cDRNWjNFZ012U2JhSGZyMmF6Wm8xUXk2X2xSQVNWcFlMVDZUdU5wZnMwVkJqNEdSaFEiLCJpc3N1ZWRfYXQiOjE0MzM0MTg2MDksInVzZXJfaWQiOiIxNDM3MzM0ODk5OTIwNDA5In0&access_token=CAAXUOnbG6uEBANtAd9DzWBSu4LLOEcPsu86Ny0Ir

Yes, I followed everything in Parse's Facebook login guide (made sure that all bundle IDs match, implemented all required AppDelegate methods, etc).

What exactly does this error mean and how do you solve it?

like image 808
Eric Avatar asked Jun 04 '15 11:06

Eric


5 Answers

A simple solution work for me. Just enable Keychain Sharing in Capabilities

Enable Keychain Sharing

like image 139
Cuong Lam Avatar answered Oct 21 '22 19:10

Cuong Lam


I only saw this error when I logged out, then logged back in.

My login and logout code were located in different files, as the relevant UI for login and logout are entirely different, and I had instantiated two separate FBSDKLoginManager instances. Consolidating to only one instance solved the problem for me.

like image 40
loudmouth Avatar answered Oct 21 '22 17:10

loudmouth


I've followed the workaround from totvos and its working for me as well when using FBSDKLoginKit 4.7.1 & FBSDKCoreKit 4.8:

Workaround...get the app built and copied to the phone, and then start the app from the device (not the debugger). Then, attach the debugger to the running process. This seems to get around whatever timing issue is breaking this, and the various keychain operations appear to work correctly while debugging.

Reference: https://forums.developer.apple.com/thread/4743#85335


Update:

This workaround didn't work all the time, so I ended up using @coco's answer above: https://stackoverflow.com/a/31480026/877225

like image 30
ObjSal Avatar answered Oct 21 '22 18:10

ObjSal


Apparently the only solution that worked for me is to add the Keychain Sharing Entitlement for the target.

You can find it in Project_name->target_name->Capabilities->Keychain Sharing

like image 15
Lolloz89 Avatar answered Oct 21 '22 17:10

Lolloz89


I found this problem when I upgraded to:

FBSDKCoreKit 4.4.0
FBSDKLoginKit 4.4.0
FBSDKShareKit 4.4.0.

It went away when I downgraded to:

FBSDKCoreKit 4.2.0
FBSDKLoginKit 4.1.0
FBSDKShareKit 4.1.0

I haven't had a chance to discover at what point the upgrades cause this - for example, could I have stuck with 4.3.0 for all three?

like image 14
coco Avatar answered Oct 21 '22 19:10

coco