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

Logging in as new user #41

Open lexorcist opened 14 years ago

lexorcist commented 14 years ago

I'm using [engine clearAccessToken] to logout of twitter, and then releasing and reallocating the engine to avoid the 'page not found' error that was coming up when I did that.

However, when you go to sign in again the user is actually still logged in; you just have to select 'allow' or 'deny' and to login as a different user you have to select the 'sign in as different user' link.

Is there a way to sign out fully, so that once you select to logout, you have to put your username and password in again to login?

bengottlieb commented 14 years ago

Try both clearing the access token and -releasing your engine instance; then re alloc/init it.

lexorcist commented 14 years ago

That's what I've done but it still doesn't work :( without restarting the app you still have to select 'sign in as different user' to properly logout.

bengottlieb commented 14 years ago

Are you storing the provided OAuth token? Are you clearing that out as well?

lexorcist commented 14 years ago

I don't think so; at the moment, when you select to login it just presents the view controller [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self] and that's it. Then, when you logout it does the following:

[_engine clearAccessToken]; [_engine release]; _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self]; _engine.consumerKey = kOAuthConsumerKey; _engine.consumerSecret = kOAuthConsumerSecret;

There's probably something really stupid I'm doing wrong, thanks for your replies!

bengottlieb commented 14 years ago

You should be passed some data in -storeCachedTwitterOAuthData:forUsername:. Make sure to clear this out.

lexorcist commented 14 years ago

I took the -storeCachedTwitterOAuthData:forUsername from the OAuthTwitterDemo app, which stores the data in the defaults with the key 'authData' and in -clearAccessToken the data is replaced with an empty string.

To make sure it was cleared out I just added a method that removes that object-key pair from the defaults completely when the access token is cleared; it still doesn't work.

Just in case I didn't describe my problem very well (and it's actually working as it's meant to or something):

  1. I press a sign in button, the SA_OAuthTwitterController comes up, and has a box for username and a box for password - plus an allow and a deny button.
  2. I put in my username and password and press allow.
  3. I press another button which clears the access token, releases the engine and re-alloc/init it (and now also removes the object-key pair completely from defaults).
  4. When I press the sign in button again, instead of coming up with the username and password boxes, it says "Hi (the-username)" and has the 'allow' and 'deny' buttons again.

The only way to get the username/password text fields is to press 'Sign in as a different user' which is also on the same page. Is this right? Or is this not meant to happen?

Thanks

bengottlieb commented 14 years ago

so if you clear out all this cached data, quit the app (real quit, not just send it to the background), you're still seeing the "Sign in as a different user" screen?

lexorcist commented 14 years ago

Sorry, I thought I had said - I'm trying to make it happen without closing the app? It works if you quit the app, but is there a way to do it without quitting the app?

bengottlieb commented 14 years ago

If it works when you quit, then you're probably not clearing everything out; double check to make sure you are.

Epershand commented 14 years ago

I have the same issue and I think that this is related to some "web session" embed in the UIWebView.

Did anybody got a solution to make this work ? Maybe injecting some JS to "click" on the logout link would do the job ?

BTW thanks for the contrib !

Subrat4glam commented 14 years ago

HI Friends..... I am using Twitter API oAuth for developing iphone application.... i am login successfully in my application using twitter credential.... but when i try to logout... its not working...

Please help me regarding this

Thanks Subrat Email-mailtosubrat@gmail.com

SteveB1 commented 14 years ago

Hi all, I really hope someone figures this out! I haven't been able to crack it.

petershine commented 14 years ago

I guess I found the solution for this Logout issue

In MGTwitterEngine class, there is a method called -(BOOL)clearsCookie. By default, this one returns NO, preventing clean logout until the user terminates the app.

Implement this method to return YES. You can implement it in MGTwitterEngine class, or in SA_OAuthTwitterEngine.

Using -(BOOL)clearsCookie with -(void)clearAccessToken of SA_OAuthTwitterEngine can make sure the user to logout without terminating the app.

stuzoo commented 13 years ago

I still don't seem to be able to get this to work, anyone have the code that they are using to signout?

JonConner commented 13 years ago

This is how I implemented petershine's solution (successfully):

_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self]; _engine.consumerKey = OAuthConsumerKey; _engine.consumerSecret = OAuthConsumerSecret;
[_engine setClearsCookies:YES]; [_engine clearAccessToken];

UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self]; if (controller) { [self presentModalViewController:controller animated: YES]; } else { // Take care of Twitter business here then release everything

[_engine clearAccessToken];
[_engine release];
_engine = nil;

}

You may not have to release _engine, but I haven't tested without releasing.