Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rest-client log in with authlogic

I am trying to use the Rest-client gem to do a few small tasks for my app which uses Authlogic to authenticate users. From Rest-Client's API, I see that one can post data necessary for the log-in process like this:

require 'rest_client'
RestClient.post "http://127.0.0.1:3000/user_sessions", {:user_session => {:username => 'myusername', :password => 'mypassword'}}.to_json, :content_type => :json, :accept => :json

Looking at my development log, I see that the app has logged in me and redirected me correctly to the user's private page. However, when I then tried to 'reload' the private page,

RestClient.get 'http://127.0.0.1:3000/users/1'

I am brought back to the login page again, as if I hadn't logged in. So I was wondering if this has to do with something called the session or cookies?

I have used cURL to reproduce this scenario successfully, where I use the switch '-c cookie.txt' to save information about my having already logged in, and use the switch '-b cookie.txt' for each call to tell the remote server about my authenticated-ness. I can understand this concept of like a stamp on your wrist when going in a theme-park or a bar where they know you paid. But I find no mentioning of such a mechanism in RestClient. Any help would be great to solve this. I don't mind trying other http clients, either.

Regards

like image 337
Nik So Avatar asked Feb 19 '10 22:02

Nik So


1 Answers

If you use Authlogic, you could be using the Single Use Token instead of user/pass. The Single Use Token is specifically for API calls like what it sounds like you're doing here.

See: The rdocs here

like image 183
Josh Lindsey Avatar answered Sep 20 '22 17:09

Josh Lindsey