用于devise的定制authentication策略

我需要为https://github.com/plataformatec/devise编写自定义身份validation策略,但似乎没有任何文档。 它是如何完成的?

我发现这个非常有用的代码片段,在devise谷歌组的这个线程

初始化/ some_initializer.rb:

Warden::Strategies.add(:custom_strategy_name) do def valid? # code here to check whether to try and authenticate using this strategy; return true/false end def authenticate! # code here for doing authentication; # if successful, call success!(resource) # where resource is the whatever you've authenticated, eg user; # if fail, call fail!(message) # where message is the failure message end end 

将以下内容添加到初始化程序/ devise.rb

  config.warden do |manager| manager.default_strategies.unshift :custom_strategy_name end