ruby-on-rails - Authlogic 和单一访问 token

标签 ruby-on-rails ruby ruby-on-rails-3 authlogic

我很难找到有关如何使用 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/

相关文章:

ruby-on-rails - 载波和mini_magick查找宽度和高度

ruby-on-rails - ruby on rails 参数没有被保存

ruby/hash:Chef::Node::ImmutableMash 将 Chef 属性转换为 yaml 时包含在文件中

ruby-on-rails - 运行迁移时未初始化的常量 #{MIGRATION_NAME}::#{TABLE_NAME}

ruby - 将 id 编码为数字和字母?

ruby-on-rails-3 - Rails:如何使用before_save更改基于另一个字段的字段值?

ruby-on-rails - 功能测试 Authlogic?

ruby-on-rails - 如何在 Rails 中使用 Test::Unit 测试记录器输出?

ruby-on-rails - 将 Rails 模型文件组织到子目录中

ruby-on-rails - 计算 Active Admin 仪表板(Rails、Active admin 1.0、Postgresql 数据库、postgres_ext gem)中序列化属性(数组)中值的出现次数