bengottlieb / Twitter-OAuth-iPhone

An easy way to get Twitter authenticating with OAuth on iPhone
http://www.standalone.com
799 stars 155 forks source link

Issue for Twitter applications with callback URL set #79

Closed albertodebortoli closed 13 years ago

albertodebortoli commented 13 years ago

If the Twitter application has a callback URL set, the authorization process got stuck in the view with the title "Select and Copy the PIN" and nothing can be done to complete the authentication. The view is blank.

I think the problem regards the modification of the method "locateAuthPinInWebView" in the last commit "New Javascript code for parsing for PIN results, from olamn2k." because it can't get the PIN.

Can you solve this please?

bengottlieb commented 13 years ago

I just pulled down the latest and tried assigning a call-back URL to my app. It had no problems parsing. Does the demo app work for you?

albertodebortoli commented 13 years ago

The demo app is not working with any Twitter app with a callback url set. A friend of mine has just (maybe correctly) fixed the bug. There is no need for out-of-band/PIN authentication step in the flow in his opinion. I've replace the entire else branch in webViewDidFinishLoad in SA_OAuthTwitterEngine.m with this:

[_engine requestAccessToken];

    if ([_delegate respondsToSelector: @selector(OAuthTwitterController:authenticatedWithUsername:)])
      [_delegate OAuthTwitterController: self authenticatedWithUsername: _engine.username];
      [self performSelector: @selector(dismissModalViewControllerAnimated:) withObject: (id) kCFBooleanTrue afterDelay: 1.0];

or better [self dismissModalViewControllerAnimated:YES]; since there is no reason to stare at the callback url page for 1 second. No gotPin method needs to be called.

bengottlieb commented 13 years ago

If you remove the callback, does it work? I can't this problem to repro here.

albertodebortoli commented 13 years ago

Works like a charm to me now with and without callback URL set (in the application on http://dev.twitter.com). I get the access_token, the refresh_token, the token_type and the expires_in keys in a JSON dictionary. So I suppose the OAuth flow is quite done also without the OOB step, maybe weird...

dvdh commented 12 years ago

I'm also having this issue, when the twitter app have a callback url set, login flow gets stuck at the "Select and Copy the PIN" page, this is on the iPhone 4.3 Simulator. When callback url is removed from the twitter app settings, login proceeds without any issue.

bengottlieb commented 12 years ago

Yes, I think the callback URL confuses the issue, since it's trying to call out to an app.

dvdh commented 12 years ago

I tested with just a default website set on twitter, no oauth callback URL supplied. On Sep 28, 2011 6:41 PM, "Ben Gottlieb" < reply@reply.github.com> wrote:

Yes, I think the callback URL confuses the issue, since it's trying to call out to an app.

Reply to this email directly or view it on GitHub:

https://github.com/bengottlieb/Twitter-OAuth-iPhone/issues/79#issuecomment-2233106

newacct commented 12 years ago

Other libraries like ShareKit allow you to specify the callback URL along with the key and secret, and it works perfectly.

albertodebortoli commented 12 years ago

ShareKit is dead. Last commit on November 23, 2010. Actually Twitter-OAuth-iPhone is the best choice out there.

ashishawaghad commented 12 years ago

Having the same issue. The page redirects to the callback URL and the authenticatedWithUsername: method never gets called in the delegate. I replaced the else code in webViewDidFinishLoad in SA_OAuthTwitterViewController (not in SA_OAuthTwitterEngine) like @albertodebortoli said and its working fine for me. Has this worked well for you @albertodebortoli so far?

albertodebortoli commented 12 years ago

My patch worked for me, but I'm not so confident with OAuth to be sure that is correct.

sek commented 12 years ago

+1 on alertodebortoll and difficultashish's solution:

This is an essential fix if you want to have other clients (who use callback urls as intended) to authenticate against the same Twitter App as your iOS app using Twitter-OAuth-iPhone

Here's what the entire method looks like for me now in SA_OAuthTwitterViewController.m (for anyone who wants to cut and paste a whole method)

- (void) webViewDidFinishLoad: (UIWebView *) webView {
    _loading = NO;
    //[self performInjection];
    if (_firstLoad) {
        [_webView performSelector: @selector(stringByEvaluatingJavaScriptFromString:) withObject: @"window.scrollBy(0,200)" afterDelay: 0];
        _firstLoad = NO;
    } else {
        // This else clause modified to work with twitter apps that have the callback URL set: https://dev.twitter.com/apps/
        // Bug details: https://github.com/bengottlieb/Twitter-OAuth-iPhone/issues/79
        [_engine requestAccessToken];

        if ([_delegate respondsToSelector: @selector(OAuthTwitterController:authenticatedWithUsername:)])
            [_delegate OAuthTwitterController: self authenticatedWithUsername: _engine.username];
        [self dismissModalViewControllerAnimated:YES];
    }

    [UIView beginAnimations: nil context: nil];
    _blockerView.alpha = 0.0;
    [UIView commitAnimations];

    if ([_webView isLoading]) {
        _webView.alpha = 0.0;
    } else {
        _webView.alpha = 1.0;
    }
}
onederrsiva commented 12 years ago

@sek Working Seamlessly, Thank you so much. BTW, when we enter wrong credentials, it dismisses the login view. Do you have any fix for this? Thanks!

lenhhoxung86 commented 11 years ago

Hi everyone, I used the patch above in my code and my app run well with callback url is set for a long time. However, several days ago, I cannot login Twitter from my app. The patch seems to be inapplicable anymore. Does anyone know how to fix it?

riyazgit commented 11 years ago

Hey Guys , its stop working for me also. Anyone knows how to fix it. Please reply early. My live app on appstore stop working.

riyazahemad commented 11 years ago

@Alberto De Bortoli have any fix for this problem again. @bengottlieb Can you fix this probelm.

lenhhoxung86 commented 11 years ago

Finally, I found the solution:

riyazahemad commented 11 years ago

@lenhhoxung86 its not working can you please share sample code or some more details. Even if the repo you refer is not working with my api key and secret key with call back url.

lenhhoxung86 commented 11 years ago

@interface OAMutableURLRequestOverride : OAMutableURLRequest { NSMutableDictionary *extraOAuthParameters;//Added for additional parameter } //Override super method

File OAMutableURLRequestOverride.m: // // OAMutableURLRequestOverride.m // //

import "OAMutableURLRequestOverride.h"

import "NSURL+Base.h"

@implementation OAMutableURLRequestOverride