react-native-fabric-twitterkit icon indicating copy to clipboard operation
react-native-fabric-twitterkit copied to clipboard

logOut not working on iOS

Open aschenkel opened this issue 8 years ago • 3 comments

When user logs out I call this function in order to remove session from asyncstorage and update state accordingly

logout(){
     FabricTwitterKit.logOut()
     AsyncStorage.removeItem('session')
     this.props.logOut()
}

When user try to log in again, it opens safari login screen but it doesn't ask for user and password as usual. Instead it automatically "logs in" user and redirect it to my app as if Twitter Client instance was saved.

Is this a bug or am I doing something wrong?

aschenkel avatar Jul 04 '17 05:07 aschenkel

It seems to be a problem with native twitter fabric iOS itself acording to this

I try adding the following to logOut method on FabricTwitterKit.m and relink library but didn't help

NSURL *url = [NSURL URLWithString:@"https://api.twitter.com"];
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
for (NSHTTPCookie *cookie in cookies)
{
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}

aschenkel avatar Jul 04 '17 06:07 aschenkel

@aschenkel I'll venture to guess you're using TwitterKit 3 here? If so, this functionality is indeed broken since SFSafariViewController is storing the previous session and if you log out all users the default behavior of TwitterKit is to use this method.

The only way I've been able to get around this is to never log out the previous user which just isn't something I can do in my app. By never logging out the previous user, TwitterKit will treat it as an "additional user" and show a UIWebView instead. This gets around the SFSafariViewController issue but has other side effects like showing the previous user's username pre-filled in the login form.

iOS 11 should sandbox the credentials of SFSafariViewController to only your app. Whether this allows you to inspect and clear credentials I haven't been able to verify, but the reason we can't do this right now is because it's global to the system. (if you iterate through [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] you'll see no twitter.com cookies present)

I made a post in the dev forums, fingers crossed they can bring back the ability to force UIWebView logins otherwise I'm stuck with v2 for awhile: https://twittercommunity.com/t/login-with-web-view/90079/3?u=albertcmartin

Ignigena avatar Aug 16 '17 21:08 Ignigena

Confirmed that logging out a user works with version 2.8.1 of the TwitterKit SDK. You can manually download here but setup might be a bit different than the Twitter docs since this was when TwitterKit was part of the Fabric suite: https://s3.amazonaws.com/kits-crashlytics-com/ios/com.twitter.sdk.ios/2.8.1/com.twitter.sdk.ios-manual.zip

Ignigena avatar Aug 16 '17 22:08 Ignigena