Question

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.

Was it helpful?

Solution

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:

OTHER TIPS

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: Using a REST API and iPhone/Objective-C

This link answers the question of how to auth an Objective-C app against rails and store the login/password in user defaults for later use:

HTTP authentication between devise and iphone app

Use the method above to add authentication to your Cocoa / Objective-C / Iphone / Mac OS X app against a Ruby On Rails backend.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top