uber / rides-ios-sdk

Uber Rides iOS SDK (beta)
https://developer.uber.com/docs
MIT License
371 stars 123 forks source link

LoginManager.executeNativeAuthenticators returns `nil` error on iOS 13 #262

Open RaytIgor opened 4 years ago

RaytIgor commented 4 years ago

Good Day!

I am having issues authorizing via rides sdk. The authorization issue came up with ios 13. The difference in behaviour between iOS 12 and iOS 13 takes place in the executeNativeAuthenticators method in the LoginManager class:

private func executeNativeAuthenticators(authenticators: [UberAuthenticating], completion: @escaping ((_ fallback: Bool) -> Void)) {
        var fallback: Bool = false
        AsyncDispatcher.exec(for: authenticators.map({ return $0.authorizationURL }),
                             with: { (url: URL) in
                                self.authenticator = authenticators.first(where: { $0.authorizationURL == url })
                             },
                             asyncMethod: DeeplinkManager.shared.open(_:completion:),
                             continue: { (error: NSError?) -> Bool in
                                fallback = false

                                if error == nil {
                                    // don't try next native authenticator
                                    return false
                                }

                                // If the user rejected the attempt to call the Uber app, don't use fallback.
                                if self.loginType == .native, error?.code == DeeplinkErrorType.deeplinkNotFollowed.rawValue {
                                    self.loginCompletion(accessToken: nil, error: UberAuthenticationErrorFactory.errorForType(ridesAuthenticationErrorType: .unableToPresentLogin))

                                    // don't try next native authenticator
                                    return false
                                } else {
                                    fallback = true
                                }

                                // try next native authenticator
                                return true
                             },
                             finally: {
                                completion(fallback)
                             })
    }

My authenticator URL is uberauth://connect?third_party_app_name=[REDACTED]&callback_uri_string=[REDACTED]://oauth/consumer&client_id=[REDACTED]&scope=[scopes]&sdk=ios&sdk_version=0.12.0

On iOS 12, I’m seeing the closure passed to continue param returns true. The error given in the closure is non-nil, thus logic continues and authorizes my application. However, on iOS 13 I’m seeing the error is nil so it returns false immediately, thus the authorization logic exists right away Then I receive [REDACTED]/oauth/consumer?error=jwt_creation_failure from AppDelagate application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) And finally, I receive “The server was unable to understand your request” from loginButton(_ button: LoginButton, didCompleteLoginWithToken accessToken: AccessToken?, error: NSError?)

FYI, the authorization via web browser still works as expected.

The same issue reported on StackOverflow: https://stackoverflow.com/questions/58868478/uber-sso-errors-with-jwt-creation-failture

Igorsnaki commented 4 years ago

+1 also receive the same issue starting from iOS 13.2

RaytIgor commented 4 years ago

@Igorsnaki did you manage to find any workaround?