authenticate_or_request_with_http_token永远不会通过

时间:2013-09-21 14:57:50

标签: authentication ruby-on-rails-4 http-authentication

我正在尝试从railscast tutorial之后为我的rails API实施身份验证。我正在使用方法authenticate_or_request_with_http_token,我应该检查块内的令牌,如果块返回true,它应该通过。但是,即使我在块中输入true,该方法也不会通过。这就是我在日志中看到的内容:

我正在使用rails 4.0

  Filter chain halted as :restrict_access rendered or redirected

这是我的代码:

  before_filter :restrict_access

  def restrict_access
    authenticate_or_request_with_http_token do |token, options|
      true
    end
  end

2 个答案:

答案 0 :(得分:3)

您的后端必须提供身份验证标头。例如 - '授权'=> “令牌令牌=#{@ token}”。如果方法找不到标题,则返回http状态403:Access forbidden

答案 1 :(得分:1)

如果您使用的是Postman,我可以将其与以下配置配合使用:

Authorization Type: "API Key"
key: "Authorization" 
value: "Token YOUR_TOKEN" (i.e. "Token abcd1234")
Add To: "Header"
相关问题