I need to write a custom authentication strategy for https://github.com/plataformatec/devise but there doesn't seem to be any docs. How's it done?
AuthenticationStrategy is a standard interface that the @loopback/authentication package understands. Hence, any authentication strategy that adopts this interface can be used with @loopback/authentication . Think of it like the standard interface for Passport.
Devise is an excellent authentication system made for Rails that allows us to easily drop-in User functionality into our project. Add Devise to your Gemfile and run bundle install. gem 'devise', '~> 3.4.0'
I found this very helpful snippet in this thread on the devise google group
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
add following to initializers/devise.rb
config.warden do |manager| manager.default_strategies.unshift :custom_strategy_name end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With