![](/img/trans.png)
[英]Custom Authentication Strategy for Devise Using :token_authenticable
[英]Custom authentication strategy for devise
我在设计谷歌组的这个帖子中找到了这个非常有用的片段
初始化/ 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
将以下内容添加到initializers / devise.rb中
config.warden do |manager|
manager.default_strategies.unshift :custom_strategy_name
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.