Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Random LoginManager logIn Errors #286

Closed
landonturner opened this issue Oct 24, 2018 · 12 comments
Closed

Random LoginManager logIn Errors #286

landonturner opened this issue Oct 24, 2018 · 12 comments
Labels
bug Something is broken or being fixed objc sdk This issue is associate with underlying Objective-C SDK

Comments

@landonturner
Copy link

Random LoginManager logIn Errors. Code=308

Environment

  • Xcode Version: 10.0 (10A255)
  • Swift Version: 4.2
  • Installation Platform & Verison: Carthage version 0.31.1
  • Using latest facebook/facebook-sdk-swift

Issue Details

I am getting sporadic Error Domain=com.facebook.sdk.login Code=308 "(null)" errors when trying to use the login manager like so:

let loginManager = LoginManager()

loginManager.logIn(readPermissions: [.publicProfile, .email], viewController: self) { loginResult in
    switch loginResult {
    case .failed(let error):
        print(error)
    case .cancelled:
        print("Facebook Login Cancelled")
    case .success:
        print("Facebook Login Success")
    }
}

My initialization code in AppDelegate.swift

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
    }

There is a similar issue here, however, the resolution of enabling keychain sharing in my app did not fix my problem. Retrying logging in eventually works.

@lemonandlime
Copy link

Im having the exact same Issue and was just gonna post it. To verify that this was a bug I created a clean project and only added the facebook button and the necessary keys in info plist and it fails about 1 out of 4.
Should be easy to reproduce.
This needs to be fixed before I can use the SDK live.

@bazoooki
Copy link

having the same problem.

@lostatseajoshua lostatseajoshua added the bug Something is broken or being fixed label Oct 26, 2018
@rinat-enikeev
Copy link

rinat-enikeev commented Oct 28, 2018

same problem.

Looks like error is FBSDKLoginErrorBadChallengeString.

The strings differs in one symbol:
In FBSDKLoginManager.m line 232 - 236.
challenge received: mH0/43TiAwd 0jyfRil7rkNdnBI=
challenge expected: mH0/43TiAwd+0jyfRil7rkNdnBI=

This plus symbol causes the error.

In FBSDKUtility.m line 65-67.

return [value stringByReplacingOccurrencesOfString:@"+" withString:@" "].stringByRemovingPercentEncoding;

Resolution: challenge received can contain plus symbol, and URLDecode replaces it with space explicitly. Challenge expected and received are not equal - and that's the reason of error.

@lostatseajoshua what can be the solution for this bug? Is it: don't send + in challenge from FB servers, or don't replace + symbol with space in URLDecode method?

For anyone who wants to fix this issue manually (quick and dirty method), please check the PR: facebook/facebook-ios-sdk#922

rinat-enikeev added a commit to rinat-enikeev/facebook-objc-sdk that referenced this issue Oct 28, 2018
Discussion: challengeReceived will never contain '+' symbol, reason:
in FBSDKUtility.m line 65-67, URLDecode explicitly replaces '+' signs with ' '.
Do the same for stored in keychain challengeExpected.
Related to special symbol '+'  in url encoded string.
@elad823
Copy link

elad823 commented Oct 28, 2018

same problem.

Looks like error is FBSDKLoginErrorBadChallengeString.

The strings differs in one symbol:
In FBSDKLoginManager.m line 232 - 236.
challenge received: mH0/43TiAwd 0jyfRil7rkNdnBI=
challenge expected: mH0/43TiAwd+0jyfRil7rkNdnBI=

This plus symbol causes the error.

In FBSDKUtility.m line 65-67.

return [value stringByReplacingOccurrencesOfString:@"+" withString:@" "].stringByRemovingPercentEncoding;

Resolution: challenge received can contain plus symbol, and URLDecode replaces it with space explicitly. Challenge expected and received are not equal - and that's the reason of error.

@lostatseajoshua what can be the solution for this bug? Is it: don't send + in challenge from FB servers, or don't replace + symbol with space in URLDecode method?

For anyone who wants to fix this issue manually (quick and dirty method), please check the PR: facebook/facebook-objc-sdk#922

Thanks a lot rinat , that solved the issue.

@codytwinton codytwinton added the objc sdk This issue is associate with underlying Objective-C SDK label Oct 29, 2018
@codytwinton
Copy link
Contributor

This PR shows that the error is in the underlying ObjC SDK: facebook/facebook-ios-sdk#922

Closing this issue for now. Follow along with the mentioned PR for details.

facebook-github-bot pushed a commit to facebook/facebook-ios-sdk that referenced this issue Oct 31, 2018
Summary:
Original issue: facebookarchive/facebook-swift-sdk#286

Discussion: challengeReceived will never contain '+' symbol, reason:
in FBSDKUtility.m line 65-67, URLDecode explicitly replaces '+' signs with ' '.
Do the same for stored in keychain challengeExpected.
Related to special symbol '+'  in url encoded string.

- [+] sign [contributor license agreement](https://developers.facebook.com/opensource/cla)
- [+] describe the change (for example, what happens before the change, and after the change)

Before the change: login fails with 308 error if challenge contains `+` sign.
After the change: no random login failures.
Pull Request resolved: #922

Reviewed By: dreamolight

Differential Revision: D12852620

Pulled By: codytwinton

fbshipit-source-id: 4ae370074b3f65cde64a4deaa0f983f9feee70db
@kamrankhan07
Copy link

I am still getting this error 1 out of 5 times, on checking I found the following
challengeReceived: RMu4wR/wSbFRzyKk0VfvpvaLs+w=
challengeExpected:RMu4wR/wSbFRzyKk0VfvpvaLs w=
Seems like this time the hotfix is causing issue now, challengeReceived is working with '+'. I am using version 4.39.0

@kamrankhan07
Copy link

Another example
challengeReceived: t4ZXt4GNj4d0mL++dEzZIk/xLj0=
challengeExpected: t4ZXt4GNj4d0mL dEzZIk/xLj0=
Looks like someone else from developer team or server side fixed the issue with '+' and its being received correctly now but on client side its causing issue because SDK is replacing '+' with ' '
@rinat-enikeev @codytwinton

@bptstmlgt
Copy link

@kamrankhan07 I was experiencing the issue with 4.38. Updated to 4.39.1, still getting the same error, sporadically. What's "weirder" is that it seems that, if I perform the login more "slowly", I won't get the error. If I do it fast (natural pace), it will trigger the error almost every time.

Let me know how you got this working (downgrade to 4.37?). Thanks!

@kamrankhan07
Copy link

@bptstmlgt please check this link

I was facing another issue stating something like "Software caused connection abort", on checking I found the above link, you can check the description there. I think your issue is most likely this one that I faced. I implemented suggestion A and it works 5/5 times now.
However I am still not sure about the other issue with challenge string, for now it doesn't happen. I am using the latest sdk from pods without any changes to it. You should also clean your 'derived data' folder after getting the latest pod and before running the code.

    pod 'FacebookSDK', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
    pod 'FBSDKCoreKit', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
    pod 'FBSDKShareKit', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
    pod 'FBSDKLoginKit', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'

@bptstmlgt
Copy link

@kamrankhan07 I just did that indeed, right after my comment (clean build + derived data) and so far the issue is gone. Thanks for the quick answer!

@ciprian-antal-3PG
Copy link

ciprian-antal-3PG commented Feb 27, 2019

I am still getting this error 1 out of 5 times, on checking I found the following
challengeReceived: RMu4wR/wSbFRzyKk0VfvpvaLs+w=
challengeExpected:RMu4wR/wSbFRzyKk0VfvpvaLs w=
Seems like this time the hotfix is causing issue now, challengeReceived is working with '+'. I am using version 4.39.0

Same for me, using version 4.38.1. Any updates on this issue? Works like a charm without the hotfix.

@robtimp
Copy link
Contributor

robtimp commented Feb 27, 2019

@ciprian-antal-3PG It was fixed again in 4.39.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something is broken or being fixed objc sdk This issue is associate with underlying Objective-C SDK
Projects
None yet
Development

No branches or pull requests