سؤال

أحتاج إلى كتابة استراتيجية مصادقة مخصصة لـ https://github.com/plataformatec/devise ولكن لا يبدو أن هناك أي مستندات. كيف يتم ذلك؟

هل كانت مفيدة؟

المحلول

لقد وجدت هذا المقتطف المفيد للغاية في هذا الموضوع على مجموعة Google Group

المهيئات/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 

أضف ما يلي إلى المبدعين/inpeise.rb

  config.warden do |manager| 
     manager.default_strategies.unshift :custom_strategy_name 
  end 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top