crino / instagram-ios-sdk

Instagram SDK for iOS
http://www.followgram.me
228 stars 63 forks source link

How to logout and clear the safari credentials? #4

Closed sauloguerra closed 11 years ago

sauloguerra commented 11 years ago

Hey Crino,

I want to thank you by the API, it is great!!

But I have a problem with logout feature, I don't know if it's a bug or a question... When I call logout, the API invalidate the access token in the application's scope, it works great, but the login still alive in the safari's scope... so, if I want to login with other different user, I can't. How can I do that?

Seems that facebook API has the same issue: http://stackoverflow.com/questions/6226950/facebook-ios-sdk-logout-question

But there is a work around to avoid this: https://github.com/facebook/facebook-ios-sdk/pull/242/files

I have tried to find out how to do this in your API, but still nothing...

Can you help me?

(sorry my english!)

crino commented 11 years ago

Hi @sauloguerra yeah seems to be a iOS 'limit' :( You could try to click on 'Not [user]?'

Apolotary commented 11 years ago

Hey everyone,

I've found a simple workaround for this issue. It's not the most elegant, but still may be useful.

In the Instagram.m where authorizeWithSafary method is located, instead of opening the generated igAppUrl string in Safari, send a notification with this string to some webview which will handle instagram login page.

Then watch for a current request in shouldStartLoadWithRequest. The request with actual redirect URI usually ends with error, so when you catch this request (don't forget to check for your app's redirect URI though), hide your webview.

At the same time you'll receive this URI, your application will be already handling the rest of authorization logic, as if you were authorising with Safari. However, if your app doesn't receive this URI, you can also manually grab that from request and manually call delegate's handleOpenURL method.

With such approach, the logout logic will work as expected, since we're clearing our app's instagram-related cached data. However, I don't think this is a good practice, since we're redirecting to our app from our app in this case.

Maybe transferring handleOpenURL method's logic to some other notification-based methods would be better, but I didn't have much time to try that.

Also, thanks for making this awesome SDK, @crino! :D

goodmanager2011 commented 10 years ago

Let says:

-(void) doLogout { NSHTTPCookie cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [storage cookies]) { NSString domainName = [cookie domain]; NSRange domainRange = [domainName rangeOfString:@"instagram.com"]; if(domainRange.length > 0) { [storage deleteCookie:cookie]; } }

} -(void) checkLogined { isLogin = NO;

mWebView = [[UIWebView alloc]initWithFrame:CGRectZero];
mWebView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
mWebView.scrollView.bounces = NO;
mWebView.contentMode = UIViewContentModeScaleAspectFit;
mWebView.delegate = self;
NSDictionary *configuration = [InstagramEngine sharedEngineConfiguration];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?client_id=%@&redirect_uri=%@&response_type=token&scope=likes+comments", configuration[kInstagramKitAuthorizationUrlConfigurationKey], configuration[kInstagramKitAppClientIdConfigurationKey], configuration[kInstagramKitAppRedirectUrlConfigurationKey]]];
[mWebView loadRequest:[NSURLRequest requestWithURL:url]];

}