Подтвердить что ты не робот

Индивидуальная стратегия аутентификации для разработки

Мне нужно написать собственную стратегию аутентификации для https://github.com/plataformatec/devise, но, похоже, не существует каких-либо документов. Как это делается?

4b9b3361

Ответ 1

Я нашел этот очень полезный фрагмент в этот поток в разрабатываемой группе google

инициализаторы/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