Reputation: 151056
In Restful Authentication, lib/authenticated_system.rb
,
why does current_user
do a login_from_basic_auth
, which does a authenticate_with_http_basic
, which is to check the HTTP user provided login name and password?
I thought the login form is in /session/new
(or /login
), and then it POST to /session
, which will go to the sessions
controller, create
action, and there, it
verifies the login name and password provided by the user.
This is line 8 of lib/authenticated_system.rb
def current_<%= file_name %>
@current_user ||= (login_from_session
|| login_from_basic_auth
|| login_from_cookie) unless @current_user == false
end
So the question is, if the login name and password was previously verified, then why checking it in current_user
?
Upvotes: 2
Views: 578
Reputation: 34350
This function indicates that there are three ways to authenticate in your system:
Even though your basic login happens with a POST request from /session/new or /login, the only thing that POST request actually does is set the session user id (probably session[:user_id]). Once that session[:user_id] has been set, you no longer need to login to perform a request, because you are authenticated. From this point forward the actual authentication happens by checking the session[:user_id] to see if someone has already logged in.
Here is a more detailed authentication lifecycle (for login):
Here is a more detailed authentication lifecycle (for HTTP BASIC authentication):
Here is a more detailed authentication lifecycle (remember me cookie):
Upvotes: 3