开发者

Rest-client log in with authlogic

开发者 https://www.devze.com 2022-12-20 22:07 出处:网络
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 pro

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,

Re开发者_如何学运维stClient.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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号