簡體   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