Rack Warden: how can I access the message passed to the fail! method?
Question
When failing an authentication strategy in Warden, a message can be passed to the fail!
method. How can I access this message in my default failure application action such that I can display it in a flash message? I tried request.env['warden'].message
, but after looking at the code for Warden::Proxy
this variable is only set for winning strategies. Thoughts?
Solution
Perhaps a different way of failing strategies (from recent documentation), is to use throw(:warden, :foo => 'bar')
. Anything you throw with will be available in your failure application through request.env['warden.options']
, including a string of the desired url as well. HTH
OTHER TIPS
When using the fail or fail! methods, you can obtain the failure message from the environment warden object.
Example:
def unauthenticated
flash[:alert] = env["warden"].message unless env["warden"].message.blank?
end
http://www.rubydoc.info/github/hassox/warden/Warden/Proxy#message-instance_method