views:

306

answers:

2

Hi,

I have a Rails application for which I use devise to authenticate my users and this works great. I now want to write an iPhone application (not just a WebUI but a proper APP) that accesses the same data and so requires the same authentication. How should I go about doing this?

I want to login using devise and keep the session open so that queries back and forth work as they do on my website. I am very new to both rails and devise.

Cheers.

A: 

This is a very general answer, but you probably want to use a webservice, in this case exposed within the devise api.

On the iPhone side, it's a web service call, see the docs for "URL Loading System Programming Guide" in the iphone sdk, or maybe this answer: http://stackoverflow.com/questions/2264092/using-a-rest-api-and-iphone-objective-c

NWCoder
Thanks for the quick reply NWCoder. Unfortunately I still don't know what to do with this now. In fact I am not even writing the iPhone App, a colleague of mine is, he is just asking me for a login API that he can call to logon and the sustain the login-session on subsequent requests. Do you think you can give me some more details? Much appreciated.
InfectiouSoul
A: 

I'm trying to do the same thing actually. I also have a Rails application, using the Devise Authentication Gem that I would like to create an iPhone App for. I don't know if I have a good answer for you yet, but here's some things I've learned along the way...

According to the README on the Devise GitHub page, it seems that Devise is implementing RESTful authentication with these 2 modules:

Database Authenticatable:

encrypts and stores a password in the database to validate the authenticity of an user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.

Token Authenticatable:

signs in an user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.

With HTTP Basic Authentication, your iPhone app won't have to re-authenticate with each request. You will only have to authenticate once, then the framework will remember that it has authenticated.

A few resources that may be helpful for you getting started:

Andrew