Implementing oAuth login w/ Facebook - getting 'isCancelled' when user declines email permissions

91 views Asked by At

I am working on the frontend implementation of facebook authentication for an app using FBSDK 4.0. I'm specifically using FBSDKLoginManager to handle the login dialog flow. On tapping a custom continue with facebook button, I trigger the oAuth flow. The app then pushes to a native Facebook app, or a safari view controller and requests authorization with email permission. When they just agree, the completion handler: handler is invoked with the error and result and I will have no error and results.isCancelled is NO.

However, if I go through the dialog flow again but decline the email permission, the completion handler is invoked with result.isCancelled as YES. Therefore, I never enter the else block to send the access token to the backend.

But I'm now confused because as I see things declining the email permission is not cancelling. In fact there is a completely separate 'cancel' option in the facebook safari flow that I'm not tapping. I need to send the access token to back end in both cases, so even if the email is not present. I could just get rid of the result.isCancelled conditional but it turns out that result.token is nil. I seem to be able to get a token through [FBSDKAccessToken currentAccessToken].tokenString but I'm not sure if that is still valid given the login seems to have failed.

What am I missing here?

[login logInWithReadPermissions: @[@"email"]
                 fromViewController:self
                            handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
                                if (error) {
                                    NSLog(@"Process error");
                                } else if (result.isCancelled) {
                                    // result is cancelled simply by declining email permissions.
                                    NSLog(@"Cancelled");
                                } else {
                                 // pass access token to back end to synchronize with our own user account
                                }
}];
0

There are 0 answers