twitter-kit-ios icon indicating copy to clipboard operation
twitter-kit-ios copied to clipboard

Any trick to force persisting user session with `TWTRSessionStore`?

Open tadija opened this issue 6 years ago • 6 comments

Since TwitterKit 3.2.1 (and in 3.3.0) user session is not persisted after the app is closed, so user has to repeat login procedure on each app launch. For some reason, this is not the case only if the app is opened in debug mode from Xcode.

I'm wondering if anyone found some workaround for this (within TwitterKit)?

I've tried to manually call saveSession: upon successful login, but that didn't make a difference. Also reloadSessionStore or sessionForUserID: or just delaying the call to sessionStore didn't help.

I guess it fails somewhere after unsafeLoadAllUserSessions so authSessionCache remains empty, but I don't have idea why.

tadija avatar May 14 '18 20:05 tadija

Is this true? No persisting? Actually I am still using the previous, closed-source, version of TwitterKit. I've made my own client to replace TwitterKit, and the last thing I need to do is migrate existing tokens. So yeah it's not exactly related to this but chances are current TwitterKit session persistence is the same as in previous versions...

zapjonny avatar Jun 28 '18 02:06 zapjonny

@zapjonny I think you should be fine with that version, this is regression in the last 2 (open source) versions.

tadija avatar Jun 28 '18 08:06 tadija

Yes, it was sub-par so I never started using it. And now it's being deprecated, which is really the reason why I ended up here.

Anyway I figured out how to excavate existing TwitterKit oauth sessions using the method I described above. I just looked around in the open-sourced twitterkit session saving classes to figure out how to do it. Somehow persistence looks like it SHOULD work even with the newer opensource twitterkit lib, but I'll never now... and now I'm close to fully migrating away.

zapjonny avatar Jun 28 '18 08:06 zapjonny

Here is what I did https://gist.github.com/jonnyijapan/8330876807be71a8237b26b5f13d70ad

zapjonny avatar Jun 28 '18 09:06 zapjonny

I ended up implementing a temporary workaround for this issue which goes like this:

  1. After the initial login with TwitterKit, manually save retreived session's authToken and authTokenSecret somewhere secure (ie. Keychain). Also, remember to clear this data when user logs out.

  2. Later on the next app start, manually pull out this data and if it exists use it to call saveSessionWithAuthToken:authTokenSecret:completion method on TWTRTwitter.sharedInstance().sessionStore. In completion check if session is still valid (it should be) and then continue with loading user or whatever.

So until I implement a new "TwitterKit" for my app, I'm stuck with this. At least it's no longer necessary to login each time the app is opened... :)

tadija avatar Jul 18 '18 21:07 tadija

my account has been suspended

 I think the reason is a lot of Twitter, Twitter and follow-up

I would like to apologize to you

If you would give me another chance

Thank you

Radar966 avatar Dec 16 '18 01:12 Radar966