Starting place for the Rails3 App, which will be the backend of the iphone application

I would like to start working on the idea that I have for the iphone application, but I have some problems with where to start. I would like the app to be mainly used on the iphone, but had some features in the web application, such as logging in and viewing things created from the iphone application. I launched the rails3 application and would like to use it as my backend for api / app.

I am confused as to how I should work with the authentication system so that this application can work both as a web application and in the api for the iphone application.

I want to use omniauth to login to the web app and iphone app because I want users to log in using twitter and / or fb, but I don’t know how to authenticate requests after users log in to the iPhone app, I know that some other gems, such as devise, allow things like an authenticated api key column, which makes signing api calls easier, but I think its path is too bloated from auth to use.

Can someone give me advice on how to make an authentication system that will work both as a webapp and when authentication via api from iphone.

Thanks!

+4
source share
2 answers

A few thoughts ...

I would suggest that the iOS app app looks like a web browser and sends a persistent cookie along with each request, as usual. Thus, you can use standard authentication methods, and also leave yourself open for the release of the web version of your application one day, without redoing everything.

So, the workflow will be as follows:

  • Get authentication information from user input and safely store it in the key chain to smoothly register them every time you open the application.
  • Use something like Devise for Rails server-side authentication (i.e. don't reinvent the wheel)
  • Send data to the server to create a new session.
  • Get session information from the server as a cookie
  • Save cookie in iOS app
  • Send cookie information to the server with each request
  • If they log out, destroy the cookies and keychain data that you saved in order to create a cookie every time they open the application.

NSURLConnection provides the means to accomplish most of this and even sends any stored cookies along with requests until you say so. Here's an old SO post telling about this: Objective-C Asynchronous web request with cookies

A few resources to help you with this:

Hope this helps!

+6
source

When you look at iphone applications such as slicehost or rackspace, you usually enter your username / password in the iphone settings ... so that takes care of authentication there on the phone. Most likely, depending on what you are doing, you will ask your iphone to talk to the database and return the json / xml that you will analyze in your application.

You can http_autenticate your call to your controller, which will then receive this information ... it just needs to confirm your username and password sent back to your rails application.

But, do you use iphone only for viewing applications or as an image, ala flickr or twitpic? A gallery of objects, usually images that can be sent back, perhaps?

Personally, do not worry about “bloating”. I'm just going to accept such comments, combined with questions such as this, meaning that you can worry about the wrong without knowing what is going on. I apologize if you are Richard Stallman or something else, but it must be said.

0
source

All Articles