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"]

    { (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:


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

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
 action:@selector(loginButtonClicked) forControlEvents:UIControlEventTouchUpInside];

// Once the button is clicked, show the login dialog
  FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    logInWithReadPermissions: @[@"public_profile"]
                     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    if (error) { 
      NSLog(@"Process error");
    } else if (result.isCancelled) {
    } 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.



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];