本文介绍了设计的自定义身份验证策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要为 https://github.com/plataformatec/devise 编写自定义身份验证策略但似乎没有任何文档.它是怎么做的?
I need to write a custom authentication strategy for https://github.com/plataformatec/devise but there doesn't seem to be any docs. How's it done?
推荐答案
我在 此主题 在设计谷歌组
初始化器/some_initializer.rb:
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
将以下内容添加到 initializers/devise.rb
add following to initializers/devise.rb
config.warden do |manager|
manager.default_strategies.unshift :custom_strategy_name
end
这篇关于设计的自定义身份验证策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!