views:

344

answers:

2

Anybody have any ideas? The situation is like this: I have a primary rails app and an auxiliary one. The auxiliary app is used to transform a web service request into a RESTful PUT to the main app. The resource the auxiliary app is attempting to add to requires authentication. Any ideas would be much appreciated! Thanks SO!

+1  A: 

ActiveResource is used for this purpose:

class MyModel < ActiveResource::Base
  self.site = OTHER_APP_URL
  self.user = OTHER_APP_USER
  self.password = OTHER_APP_PASSWORD

  # Rest of the code here
end

Read up on how to talk to RESTful API from ActiveResource here: http://api.rubyonrails.org/classes/ActiveResource/Base.html

Swanand
Thanks Swan, I did not see your answer before adding my own. This would definitely work, and I almost resorted to HTTP authentication, however I found a way to leverage my current RESTful authentication scheme involving the RESTful_authentication and Curb gems.
Reuben Peter-Paul
I was discussing this issue with a friend of mine with more exp in RESTful webservices and argued that introducing state (via sessions) breaks the REST model which is why Rails undoubtedly provides such great mechanisms as the one you describe above.
Reuben Peter-Paul
A: 

I think I may have found my own answer by polling some of my IM contacts. The most logical approach is to use the Curb ruby gem. From the aforementioned API, one simply enables the cookie jar, restfully authenticates and then includes the cookie in subsequent HTTP actions requiring authentication ;)

(Will post some code when I get this implemented..)

Would still appreciate comments and or alternatives though!

Reuben Peter-Paul
ActiveResource is made for this purpose, provides a lot of utility methods and awesome abstraction. It is highly recommended. Thanks for the pointer on Curb though, I will surely check it out.
Swanand