Ruby on rails 定制设备:验证用户过滤器,同时检查验证令牌
我希望能够自定义:authenticate\u user过滤器,以包括通过身份验证令牌对用户进行身份验证。我不想使用内置令牌机制的原因是,它只允许一个auth令牌。我希望用户拥有多个令牌。据我所知,Desive不支持这一点Ruby on rails 定制设备:验证用户过滤器,同时检查验证令牌,ruby-on-rails,devise,Ruby On Rails,Devise,我希望能够自定义:authenticate\u user过滤器,以包括通过身份验证令牌对用户进行身份验证。我不想使用内置令牌机制的原因是,它只允许一个auth令牌。我希望用户拥有多个令牌。据我所知,Desive不支持这一点 有什么想法吗?我添加了自己的策略来解决这个问题: Warden::Strategies.add(:tokens_authenticatable) do def valid? # code here to check whether to try and aut
有什么想法吗?我添加了自己的策略来解决这个问题:
Warden::Strategies.add(:tokens_authenticatable) do
def valid?
# code here to check whether to try and authenticate using this strategy;
return params.key? :token
end
def authenticate!
# code here for doing authentication;
puts params
token = Token.where(["token = ?", params[:token]]).first
puts token
if (!token.nil?)
# if successful, call
success!(token.user) # where resource is the whatever you've authenticated, e.g. user;
else
# if fail, call
fail!("WWAAAAA") # where message is the failure message
end
end
end
config.warden do |manager|
# manager.intercept_401 = false
manager.default_strategies(:scope => :user).unshift :tokens_authenticatable
end