I am trying to get up a simple authentication system with Rails' Restful-Authentication plugin, and am just wondering how it works, b/c I can't seem to figure out what the requirements are for cookies, and how to make it so the browser always remembers you (for 6+ months).
Few questions:
1) How do you do remember_me's for ruby's restful_authentication? I can't seem to find a good one-liner to solve this problem...
If a user signs up and checks "Remember Me", how does the rails application get the session/cookie without the user doing anything but going to the page the next time they go to the page, say 3 months later?
2) Do I need to send some sort of info to the server, like their IP address or something? What is cookies[:auth_token]
, where is that defined?
The goal is: I don't want them to have to enter their email/password again, like how StackOverflow works :)
You can find here a whole tutorial about restful authentication. http://railsforum.com/viewtopic.php?id=14216&p=13
I'm honestly not sure aboout that particular implementation. But a common RESTful method of authentication is to pass a hashed version of the user/password with each request as a header. Alternatively you can use a hashed cookie value as a header.
I've also seen hybrid systems that involve both. You pass in the session, if you know it, in addition to the user/pass. Then server side if the session is valid it uses that and can cache the session - > user relationship for performance. If the session is invalid, it attempts to authenticate using the user/pass.
In this type of system you'd pass the session back on the response as a header.
Of course that's just a quick rundown of how a system might work, not how ruby's library does.
Here's what we're doing (largely taken from authenticated system) ... this is the controller method that handles login that we're running...
And use this for logout
Then - in your application.rb you'll need something like:
And - in your User model have some methods like this: