Skip to content

Twitter login cancellation crashes app #1474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ashish-naik opened this issue Dec 17, 2019 · 10 comments
Closed

Twitter login cancellation crashes app #1474

ashish-naik opened this issue Dec 17, 2019 · 10 comments

Comments

@ashish-naik
Copy link

ashish-naik commented Dec 17, 2019

I am using Twitter authentication without ParseUI framework.

When i initiate twitter auth session using PFTwitterUtils.logIn { (loggedInUser, error) in, the Twitter login page opens.

i am able to login using valid credentials.
But if i tap Cancel and then tap Return to app then app crashes with below error at line 61 in PFTwitterAuthenticationProvider.m

*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

Parse/TwitterUtils (1.17.3)
iOS 13.2.2 simulator

i tried breakpoints to catch flow in my code but crash happens before control returns to PFTwitterUtils.logIn { (loggedInUser, error)

What could be the issue?

Thanks
Ashish

@ashish-naik
Copy link
Author

@nlutsenko I saw #348
i am seeing similar error but in a different use case.

i had created this issue five days back but didn't get any response. I tried looking for answers on Stackoverflow also.

I have checked twitter authentication related posts but could not find any answer.

Setting callback URL is mentioned at many place. I have set it in my app dashboard and able to login also.
it fails when tap Cancel and then Return to myapp on Twitter webpage popup inside my iOS app.

Could you please suggest what could be the issue?

@drdaz
Copy link
Member

drdaz commented Dec 22, 2019

Hi Ashish

It's hard to be certain exactly what's failing without more code for context, but line 61 in that file looks like this:

    NSDictionary *authData = @{_PFTwitterAuthDataIdKey : twitterId,
                               _PFTwitterAuthDataScreenNameKey : screenName,
                               _PFTwitterAuthDataAuthTokenKey : authToken,
                               _PFTwitterAuthDataAuthTokenSecretKey : authTokenSecret,
                               _PFTwitterAuthDataConsumerKeyKey : self.twitter.consumerKey,
                               _PFTwitterAuthDataConsumerSecretKey : self.twitter.consumerSecret};

The error occurs because one (or more) of the variables after the ':' in the dictionary literal evaluate to nil at the time of the crash. My advice would be to set a breakpoint on that line and recreate the crash scenario. Once you hit that line, you'll be able to use the debugger to find out which of the variables is nil. You will likely be able to work from there to ensure that it isn't nil.

I hope this helps.

EDIT: Looking at the reason for this code, it seems odd that you would be hitting this if you're cancelling your login. Perhaps I've misunderstood your case, but if your user cancels their Twitter login, then you wouldn't want to call any 'login' methods.

@drdaz
Copy link
Member

drdaz commented Dec 22, 2019

@ashish-naik Also, you've specified that this occurs when you don't use ParseUI. Do you know whether ParseUI behaves better?

@ashish-naik
Copy link
Author

@drdaz I was using ParseUI but replaced that with my custom classes because Sign in with Apple is not available yet and added email/password based authentication. Not sure whether i was hitting this issue then with ParseUI.

I tried with the breakpoint. See attached screenshot. All variables are nil. I have also attached screenshots of Twitter screens.

Steps to reproduce are

  1. On my custom VC i tap Twitter Button
  2. Call PFTwitterUtils.logIn { (loggedInUser, error) in
  3. Twitter login popup opens
  4. I tap Cancel (first screenshot)
  5. Twitter Show page with button Return to app
  6. I tap Return to app button (second screenshot)
  7. App crash on line 61

This is happening on iOS 12.2 simulator and 13.3 device, simulator

yes after cancel i dont need to handle login but exception occurs before my login handler is called after Cancel.

TW login SS 1
TW login SS 2
breeakpoint screenshot

Does this help?

@drdaz
Copy link
Member

drdaz commented Dec 22, 2019

This looks like a bug. I don't use the Twitter login feature myself, and I can't seem to test it using the ParseUI Demo project, so it's a little hard for me to reproduce.

But it looks like it's trying to authenticate the user even though they pressed cancel. Which is... wrong.

@ashish-naik
Copy link
Author

@drdaz No i am not trying to authenticate after cancel.

My PFTwitterUtils.logIn { (loggedInUser, error) call opens the login page and then i wait to check error if any but control does not return.

@drdaz
Copy link
Member

drdaz commented Dec 22, 2019

So I've just taken a look at the Twitter auth code, and it's very outdated. It still assumes that iOS has local Twitter accounts, which hasn't been the case for several years.

Do you absolutely need Twitter login? Looking at the state of things in there, if you can avoid it, do so. Otherwise, perhaps you can take a look at the code causing the trouble. I can't spend much time on it right now.

@drdaz
Copy link
Member

drdaz commented Dec 22, 2019

That's just my opinion btw; the opinion of a guy who hasn't attempted to use the Twitter login feature at all before today.

If anybody else has been using it successfully, by all means chime in.

@ashish-naik
Copy link
Author

No I can remove Twitter.

Thanks for looking in.

@brianyyz
Copy link

FWIW I abandoned Twitter as an authentication provider for the reasons above. Even back then it was in a bit of a mess and didn't take into account the changes that Twitter has made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants