for - iOS Parse Facebook Login error 308 FBSDKLoginBadChallengeString




failed for url fbauth2:/ (14)

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?


if log out and login again without leaving this app,this error also come,

let deletepermission = FBSDKGraphRequest(graphPath: "me/permissions/", parameters: nil, HTTPMethod: "DELETE")
            deletepermission.startWithCompletionHandler({(connection,result,error)-> Void in
                println("the delete permission is \(result)")
                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    FBSDKAccessToken.setCurrentAccessToken(nil)
                    FBSDKProfile.setCurrentProfile(nil)
                    fbLoginManager.logOut()
                    AppDelegate.sharedAppDelegte().logout()
                })
            })

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


Before downgrading, I would try to clear out the local cache. I've had this problem when switching between Facebook accounts. Delete your app, force the Facebook to quit and then re-run everything and see if it persists. There may be a bug where Facebook is passing an old cached key that is no longer valid. Downgrading could be clearing the cache or the older version doesn't have the bug.


Error code 308 is FBSDKLoginBadChallengeString

Using a shared instance for the FBSDKLoginManager solves the problem. I created a singleton that makes sure, only one FBSDKLoginManager gets instantiated.

I assume it has to do with the iOS9 Safari login, not 100% sure though


Follow these steps to resolve that kind of error :

  1. Go to your project
  2. Click Capabilities
  3. Enable Keychain Access

I also had error 308, however I was not using the Parse SDK.

These errors started appearing when I upgraded the Facebook iOS SDK from version 4.0.1 (FacebookSDKs-iOS-20150402) to one of the newer versions (4.2.0 - FacebookSDKs-iOS-20150528 or 4.3.0 - FacebookSDKs-iOS-20150625).

Downgrading the Facebook iOS SDK to version 4.0.1 solved this problem for me.

As a side note: the new versions of the SDK seem to correlate well with the appearance of 308 error posts on SO at the beginning of June.


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?


I got the same problem when I was trying to catch login and logout event as below

loginButton = [[FBSDKLoginButton alloc] init];
// Handle clicks on the button
[loginButton
 addTarget:self
 action:@selector(loginButtonClicked) forControlEvents:UIControlEventTouchUpInside];

// Once the button is clicked, show the login dialog
-(void)loginButtonClicked
{
  FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
  [login
    logInWithReadPermissions: @[@"public_profile"]
          fromViewController:self
                     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    if (error) { 
      NSLog(@"Process error");
    } else if (result.isCancelled) {
      NSLog(@"Cancelled");
    } else {
      NSLog(@"Logged in");
    }
  }];
}

But this is only good for a custom login button, if you are using default fb login button, the FBSDKLoginManager has been initialized already, you will get the error when trying to create another one.

So, in order to catch login and logout event, just set the delegate for login button and then handle it like the following:

    loginButton = [[FBSDKLoginButton alloc] init];
    loginButton.delegate = self;


- (void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error {
    if (!error) {
        [self getFBProfile];
    }
}

- (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton {
    [self logout];
}

I'm using

pod 'FBSDKCoreKit', '~> 4.8.0'
pod 'FBSDKLoginKit', '~> 4.8.0'
pod 'FBSDKShareKit', '~> 4.8.0'

... and had the code 308 problem when I logged out and logged in during the same session. Using [[FBSDKLoginManager alloc] logOut] or [facebookLoginManager logOut] (with a persisted manager) just before calling logInWithReadPermissions: didn't work, but adding

[FBSDKAccessToken setCurrentAccessToken:nil];
[FBSDKProfile setCurrentProfile:nil];

before the logInWithReadPermissions: call works ok. (Tested in iOS 9.2.)


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://.com/a/31480026/877225


It's due to the authenticationChallenge issue when you mistakenly try to login twice simultaneously and then further logins will give you some keychain warning on console while debugging, this error will be noticeable when you will be debugging on device. Without debugging mode you'll not get this error, the reason is keychain will work fine when you are not debugging.

There are few workarounds for this: 1. Try logging in without debugging mode and once it succeeded you can further login successfully with debugging mode too. 2. Check for error code FBSDKLoginBadChallengeString and call [FBSDKAccessToken setCurrentAccessToken:nil] to clear token and perform login again.



Update Facebook SDK to latest version solved this.


Use the same FBSDKLoginManager instance until logout, THEN create a new instance.

[fbLoginManager logOut];
fbLoginManager = [[FBSDKLoginManager alloc] init];






parse.com