Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
There are a number of callbacks at various points in the authentication cycle available.
With all callbacks, you can add as many as you like, and they will be executed in the order they were declared. If you want to prepend a callback, you should prefix each callback name with "prepend_", e.g. prepend_before_failure, prepend_before_logout and so on, and pass the same arguments described below.
This is called every time the user is set. The user is set:
- on each request when they are accessed for the first time via env['warden'].user
- when the user is initially authenticated
- when the user is set via the set_user method
Warden::Manager.after_set_user do |user, auth, opts| unless user.active? auth.logout throw(:warden, :message => "User not active") end end
Executed every time the user is authenticated (first time in each session).
Warden::Manager.after_authentication do |user,auth,opts| user.last_login = Time.now end
This callback is run right before the failure application is called. Failures
This is useful for mutating the env if required by the rack endpoint used. For example, some endpoints may require request.params[:action] to be set to the method name.
Warden::Manager.before_failure do |env, opts| request = Rack::Request.new(env) env['SCRIPT_INFO'] =~ /\/(.*)/ request.params[:action] = $1 end
This callback is run before each user is logged out. This is useful for deleting a remember_me token from users.
Warden::Manager.before_logout do |user,auth,opts| user.forget_me! auth.response.delete_cookie "remember_token" end