What is the correct way of making “persistent” session with RestKit?
The most simple way is to make long session at the server side, but
not sure it’s safe for browser version. I prefer to implicitly re-
login if session is expired, but in this case I have to handle session
expiration, send new login request, receive response and than send
again a target request. Sources become more complicated.
Is there any features in the RestKit which allows manage that
automatically? Maybe just keep persistent session for iPhone app and
short one for web version using features of CakePHP?
Thanks,
Victor
You probably want the session in order to for authentication/authorization to work?
I’m currently working on a RestKit project on iOS. For my needs, what I did was very close to the discussionboard example by RestKit’s creators.
in iOS, you can write a
uniqueSecurityTokentoNSUserDefaults. It can be a property model of your user model on the iOS app. On Rails (Im making an assumption), if you have a auth gem like Authlogic/Sorcery, it’s very easy to either override thecurrent_usermethod or assigning one based on token.For example,
You can call a
before filterto make sure that the authentication is always checked. on the IOS side, tell RestKit to send the uniqueSecurityToken asHTTP_USER_ACCESS_TOKENin the headers. Note that this is probably not the most secure method, you should at least have HTTPS so that the transport is encrypted.Here’s the RestKit Discussion Board Project (very useful for RestKit/IOS)
https://github.com/RestKit/RKDiscussionBoard
Here’s a Rails Presentation that outlines Rails/iOS integration
http://www.slideshare.net/maximeguilbot/rails-as-ios-application-backend
If you’re using another REST framework other than Rails, you can reference the JSON techniques too.