Devise allow token authentication on single controller action

我与影子孤独终老i 提交于 2019-12-22 08:27:07

问题


I have an webapplication that uses devise database authentication for all the controllers, however I want to have one controller action where authentication is also done using a token. Can i use devise for this?


回答1:


Devise strategies have a valid? method that is called to determine if the strategy should be enabled. This allows you to control available auth strategies on a per controller/action basis.

Put this in an initializer:

require 'devise/strategies/base'
require 'devise/strategies/token_authenticatable'
module Devise
  module Strategies
    class TokenAuthenticatable < Authenticatable
      def valid?
        super && params[:controller] == "your controller" && params[:action] == "your action"
      end
    end
  end
end

let me know if it works.



来源:https://stackoverflow.com/questions/11081338/devise-allow-token-authentication-on-single-controller-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!