【发布时间】:2011-05-12 12:08:51
【问题描述】:
我需要为https://github.com/plataformatec/devise 编写自定义身份验证策略,但似乎没有任何文档。它是怎么做的?
【问题讨论】:
标签: ruby-on-rails ruby devise
我需要为https://github.com/plataformatec/devise 编写自定义身份验证策略,但似乎没有任何文档。它是怎么做的?
【问题讨论】:
标签: ruby-on-rails ruby devise
我在设计谷歌组的this thread 中发现了这个非常有用的 sn-p
initializers/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, e.g. 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
【讨论】: