![](/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.