Home:ALL Converter>Log out the user on the iOS 4 with HTTPBasicAuthentication

Log out the user on the iOS 4 with HTTPBasicAuthentication

Ask Time:2010-08-11T23:47:40         Author:Ivan

Json Formatter

I am programming an iPhone application. My (existing) web-application uses Ruby on Rails (2.3.2) to serve the data. Ruby on Rails backend uses restful-authentication gem to authenticate the users.

To get user data from the server to the iPhone app I use HTTPRiot framework and authenticate user with HTTPBasicAuthentication.

Now everything works fine - user can get and post some data to and from the iPhone app. But when I want to log out the user from the service it seems impossible. From the different topics I understood that logout was just not implemented in HTTPBasicAuthentication and I completely OK with that. I tried to find a work around like implementing a switch in the Settings.app to force my app to display the login screen when user goes back to the app.

The problem is: iOS4 keeps connection kind of "open" when app is entering background. To log out from HTTPBasicAuthenticated connection, this connection needs to be broken. Using this approach my user needs to quit the app, turn the switch on in the Settings.app, delete my app from multitasking and start my app again. This is too dirty.

My question is: is there a cleaner way to logout/change the user without completely leaving the application?

Some references: HTTPRiot, Logout and basic auth, Logout and basic auth 2

Author:Ivan,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/3460228/log-out-the-user-on-the-ios-4-with-httpbasicauthentication
yy