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.