views:

42

answers:

1

Ok here's my problem in a nutshell I've built a web service from ruby on rails. I'm using restful_authentication to create and run the login but I'm also building an iPhone application to access my web service but I can't quite figure it out. I was wondering if anyone could help me figure out a place to begin.

A: 

Are you asking from the iphone side or the rails side?

For Rails, I think you should either use the basic_authentication features of restful_authentication to take in a username password and authorize your request, or follow this article: http://www.compulsivoco.com/2009/05/rails-api-authentication-using-restful-authentication/ which lets you login via an API Key

def login_from_api_key
  self.current_user = User.find_by_api_key(params[:api_key]) unless params[:api_key].empty?
end

def current_user
  @current_user ||= (login_from_session || login_from_api_key || login_from_basic_auth || login_from_cookie) unless @current_user == false
end

The iPhone side is simpler if you use the api_key; just append it to your http headers and you'll be good to go.

Jesse Wolgamott
Sorry I should have made this clearer I'm wanting to login from the iPhone side. I don't think an api key would work because each user has a unique set of items that they've created.
Chris Maness
OK, then I would do Basic Authentication from the iPhone, and restful_authentication will handle it... you can see it does "login_from_basic_auth" in the current_user method.So for each post/get from objective-C, add the username/password. ASIHTTP does a good job: http://allseeing-i.com/ASIHTTPRequest/How-to-use
Jesse Wolgamott