The utility allows token authentication with a single controller

I have a web application that uses standard database authentication for all controllers, however I want to have one controller action, where authentication is also performed using a token. Can I use the program for this?

+4
source share
1 answer

valid? development strategies have a valid? , which is called to determine if the strategy should be enabled. This allows you to control the available authentication strategies based on each controller / action.

Put this in the 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.

+5
source

Source: https://habr.com/ru/post/1336192/


All Articles