繁体   English   中英

设计的自定义认证策略

[英]Custom authentication strategy for devise

我需要为https://github.com/plataformatec/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, e.g. user;
    # if fail, call 
    fail!(message) # where message is the failure message 
  end 
end 

将以下内容添加到initializers / devise.rb中

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM