我很难找到有关如何使用 authlogic 启用单一访问 token 身份验证的简单教程。有一些文档,但不是很有用。
我将 single_access_token 添加到我的数据库,我添加了这个:
single_access_allowed_request_types :any
到我的 session 类。但我仍然不明白如何使用每次调用传递的凭据参数对用户进行身份验证。我的 require_authentication before filter 像这样对 current_user 进行标准检查:
def current_session
return @current_session if @current_session
@current_session = Session.find
end
def current_user
@current_user = current_session && current_session.record
end
但这足以工作吗? Session.find 方法是根据我的参数神奇地记录用户,还是我必须创建单独的方法来实际检查 user_credentials 参数是否存在,然后根据它找到用户,然后让该用户登录。我很困惑,如果我每次使用 SAT 时真的在“创建”一个新 session ,或者我是否只是在每次进行 API 调用时将当前用户设置在前置过滤器中。
任何帮助都会很棒!谢谢!
最佳答案
我使用 authlogic 实现了一个 single_access_token 解决方案,我必须做的是将 single_access_allowed_request_types :all
添加到 UserSession 模型。
然后我将以下内容添加到我想要允许 single_access_token 身份验证的 Controller 中。
def single_access_allowed?
["some_action_1","some_action_2","some_action_3"].include?(action_name)
end
您似乎缺少 Controller 代码。因此,如果您有两个操作“get_user_info”和“update_user_info”,您将添加。
def single_access_allowed?
["get_user_info","update_user_info"].include?(action_name)
end
关于ruby-on-rails - Authlogic 和单一访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7906197/