25
我需要为https://github.com/plataformatec/devise编写自定义身份验证策略,但似乎没有任何文档。它是如何完成的?设计的自定义身份验证策略
我需要为https://github.com/plataformatec/devise编写自定义身份验证策略,但似乎没有任何文档。它是如何完成的?设计的自定义身份验证策略
我发现这非常有帮助的片段在this thread在色器件谷歌组
初始化/ 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
感谢,非常有用,我用它来验证我的旧网站的joomla用户:-) – simo 2012-12-20 18:52:48
非常有帮助的答案,但链接被破坏。你能纠正它吗? – mrzasa 2013-01-23 11:28:11
链接仍然适用于我。 – opsb 2013-01-23 12:49:57