Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter / Fabric login button only working once

I'm using, with success the Fabric Login button (TWTRLogInButton, https://dev.twitter.com/twitter-kit/ios-reference/twtrloginbutton).

In my Swift app I can authenticate myself, make calls and all. The only problem is that i've implemented a "Logout" button that calls Twitter.logOut().

As specified by the documentation (https://dev.twitter.com/twitter-kit/ios-reference/twitter) this deletes the local session but does not invalidate the remote session. The effect is that once I'm authenticated and then logged out, if I click the "Login" button again I'm logged-in again with the same user, effectively preventing me from switching user.

Any help?

like image 683
pistacchio Avatar asked Feb 19 '15 15:02

pistacchio


4 Answers

The logOut is a class method, did you call:

 Twitter.sharedInstance().logOut()
like image 177
Felix Dumit Avatar answered Oct 12 '22 01:10

Felix Dumit


The incomplete logout issue you guys are facing is actually more related to iOS persisting system accounts. TwitterKit automatically logs a user in if they were already logged in on iOS. You can workaround this behavioral in the use case of kiosk with these steps:

  1. Login to Twitter in Settings > Twitter
  2. Switch to your app and attempt to login with Twitter
  3. Disallow access to Twitter accounts when the grant access dialog comes up:

Twitter account access dialog

This prevents TwitterKit from accessing your system accounts and every user will have to login. Hope this helps!

(Initially Twitter.sharedInstance().logOut() destroys local session...)

like image 38
EI Captain v2.0 Avatar answered Oct 12 '22 02:10

EI Captain v2.0


use method

[[Twitter sharedInstance] logInWithMethods:TWTRLoginMethodWebBasedForceLogin completion:{}]

Parameter TWTRLoginMethodWebBasedForceLogin

  • Presents a web view that doesn't use any cached sessions from Safari. Allows the developer to provide multi-user functionality with several Twitter accounts.
like image 41
headstream Avatar answered Oct 12 '22 00:10

headstream


I came across this problem as well, but it seems that this is how it behaves, Twitter "saves" the credentials on an OS level using Accounts framework. You can see this here:

go to Settings on your phone -> Twitter and you'll see the account there go into the account and "Delete Account"

once you delete the account you will find that when you launch your app and try to login to twitter now you will be asked to sign in.

Once an account is added there is no way to take out the account, (unless Twitter supports this and makes it public) The User will have to manually go into Settings -> Twitter and delete the account from there to be able to sign in to a different account.

Also i noticed that when you add another account into Twitter, trying to login you will be given a chance to login either account when using [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error)

edit: Upon further Research if the User allows the app to use "Twitter" accounts you are able to access the Accounts Framework and delete the account from there:

https://developer.apple.com/library/mac/documentation/Accounts/Reference/ACAccountStoreClassRef/index.html

Cheers!

like image 28
CzaSalad Avatar answered Oct 12 '22 00:10

CzaSalad