Ruby on rails 设计的自定义认证策略
我需要为写一个自定义的身份验证策略,但似乎没有任何文档。怎么做的 我在Desive google group上发现了这个非常有用的片段 初始化器/some_initializer.rb:Ruby on rails 设计的自定义认证策略,ruby-on-rails,ruby,devise,Ruby On Rails,Ruby,Devise,我需要为写一个自定义的身份验证策略,但似乎没有任何文档。怎么做的 我在Desive google group上发现了这个非常有用的片段 初始化器/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 tr
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
将以下内容添加到初始值设定项/designe.rb中
config.warden do |manager|
manager.default_strategies.unshift :custom_strategy_name
end
谢谢,非常有用,我用它来验证我的老网站的joomla用户:-)非常有用的回答,虽然链接断了。您能纠正它吗?我强烈建议在实施您自己的策略时使用它作为模板,否则您可能会遇到Memberable不工作的问题,它的设置是在调用中完成的。