Im struggling to replace the default :password strategy for the Padrino-Warden gem. The way I figure it I need to get a hold of the manager instance for warden so I can set the default strategies but I'm not sure how to do that in the app.rb file
Right now app.rb looks like this
register Padrino::Warden
Warden::Strategies.add(:udid) do
def valid?
puts "udid strat"
params[:udid]
end
def authenticate!
user = User.get(:udid => params[:udid])
user.nil? ? fail!("Could not log in") : success!(user)
end
end
Warden::Manager.serialize_into_session do |user|
user.id
end
Warden::Manager.serialize_from_session do |id|
User.get(id)
end
use ::Warden::Manager do |manager|
manager.scope_defaults :default,
strategies: [:password],
action: 'sessions/unauthenticated'
end
Which does not work. The warden environment still looks like this
Warden::Proxy:70352196940440 @config={:default_scope=>:default, :scope_defaults=>{}, :default_strategies=>{:_all=>[:password]}, :intercept_401=>true, :failure_app=>Dagis}
If I configure warden in config.ru it will set the correct environment for warden but then I suspect the session middleware provided by Padrino does not work well together with Warden.
You need to instruct the warden manager when to use the strategy. Update the strategies
key that you're passing to the use
method to reflect which strategies you want to enable and the order in which they should be run. You could do this:
use ::Warden::Manager do |manager|
manager.scope_defaults :default,
strategies: [:udid, :password],
action: 'sessions/unauthenticated'
end
There's a bunch of examples on the Warden wiki on github