Problem using TwitterKit to login via OAuth

ios
fabric
oauth

#1

I’m trying to integrate TwitterKit into an existing iOS app and am having problems with the login flow. Specifically falling back to OAuth when the user does not have any credentials stored in the Apple Accounts framework. In this scenario, TwitterKit is unable to get an auth token and the error returned from the server is:

[TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <error>Desktop applications only support the oauth_callback value 'oob'</error>
  <request>/oauth/request_token</request>
</hash>
" UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <error>Desktop applications only support the oauth_callback value 'oob'</error>
  <request>/oauth/request_token</request>
</hash>
}

I’ve read in other posts that I need to:

  1. set a value in the callback url field of my fabric app definition
  2. and include the SafariServices.framework

I’ve done both but the error still occurs. Is there another configuration tweak that’s required?

Carl


#2

I’m having the same exact issue. Anyone got a solution?


#3

Hey @clt and @_skciva,

Thanks for reaching out on this. Have you made any customizations to the TWTRLoginMethod enum defined in Twitter.h along with the [Twitter logInWithMethods:completion:] method? By default, Twitter Kit will choose log in methods in the following order [System Account] -> [SFSafariViewController] -> [UIWebView]. With the TWTRLoginMethod enum, the developer can choose which methods to use when providing the user with the ability to log in using Twitter.

-Mike


#4

Hi Mike,

I have not made any customizations since I want the default behavior. Here’s my code that’s invoked when the user taps a button:

-(IBAction)connectToTwitter:(id)sender
{
    [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {
        if ( session )
        {
            if ( self.completionBlock )
            {
                self.completionBlock();
            }
        }
        else
        {
            NSLog(@"%@",error);
        }
        [self performSegueWithIdentifier:@"unwindConnect" sender:self];
    }];
}

I tried to reproduce this issue by creating a simple test app that just logged in to Twitter using the code above. It works as expected for the following scenario:

  1. used system account when present
  2. use OAuth flow when no system accounts available

The only difference between my test app and my production app is that I used the Fabric desktop app to create my fabric.io keys and integrate TwitterKit into the test app. For the production app, I had created my fabric.io keys via the website and installed TwitterKit via cocoapods.

I wonder if there’s some configuration difference between the two integration methods that’s causing the issue…

Carl


#5

Hi @bonnell, I personally haven’t modified any code included in TwitterKit. My exact call which returns the error that @clt posted is as follows:

Twitter.sharedInstance().logInWithViewController(self, methods: TWTRLoginMethod.WebBased) { session, error in
     
     guard let _ = session else {
        print("boo")
        return
     }
     
     print(session?.authToken)
  }

I’ve been able to successfully login with the call:

Twitter.sharedInstance().loginWithCompletion{}

Unfortunately this method doesn’t allow me to retrieve a users email, so it doesn’t accomplish what I’m seeking to do.


#6

Hi @bonnell and @_skciva,

For some reason my earlier reply got tagged as spam. I hope this one makes it through… I use the following code snippet to login to Twitter:

[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {
    if ( session )
    {
        if ( self.completionBlock )
        {
            self.completionBlock();
        }
    }
    else
    {
        NSLog(@"%@",error);
    }
}];

This works when user credentials exist in Apple’s system accounts but when they do not, it does not fall back to OAuth.

I tried to reproduce the issue with a simple test app that just performs a login to Twitter using the same code snippet. It actually works as expected when credentials already exist and invokes the OAuth flow when they do not.

The main difference between the test app and my production app is that for the test app, I used the Fabric desktop app to generate the app keys and install TwitterKit. For my production app, I had created the app keys on the fabric.io website and use cocoapods to download and install TwitterKit.

I wonder if there’s some difference in configuration between the two integration methods that could be causing the issue?

Carl