Question

Je dois écrire une stratégie d'authentification personnalisée pour https://github.com/plataformatec/devise mais il ne semble pas y avoir de documents. Comment est-il fait?

Était-ce utile?

La solution

Je trouve cet extrait très utile dans ce fil sur le groupe Google DEVISE

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 

ajouter à la suite initializers / devise.rb

  config.warden do |manager| 
     manager.default_strategies.unshift :custom_strategy_name 
  end 
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top