Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing a Warden strategy - how to ensure original devise_authenticable strategy is gone

I created my own Warden strategy for using with Devise. It's very similar to Devise::Strategies::DatabaseAuthenticatable and actually it inherits from it and re-implements authenticate!

My issue though is that I want to make sure the original devise_authenticable Warden strategy is gone. That is not in the list of strategies Warden will try because it's actually a security problem. Is that possible?

like image 820
pupeno Avatar asked Dec 31 '25 07:12

pupeno


1 Answers

According to my manual inspection and tests, this in the devise.rb initializer achieves the goal:

config.warden do |manager|
  strategies = manager.default_strategies(:scope => :user)
  strategies[strategies.index(:database_authenticatable)] = :alternative_strategy
end

And the strategy is implemented this way (not part of this question, but I found conflicting information out there and this one is the one that worked for me using Rails 3.1, devise 1.4.7 and warden 1.0.5):

class AlternativeStrategy < Devise::Strategies::Authenticatable
  def authenticate!
  end
end
Warden::Strategies.add(:alternative_strategy, AlternativeStrategy)
like image 55
pupeno Avatar answered Jan 02 '26 00:01

pupeno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!