authentication_or_request_with_http_token 从不通过

har*_*nsa 2 authentication http-authentication ruby-on-rails-4

我正在尝试按照railscast 的本教程为我的 rails API 实现身份验证。我正在使用方法authenticate_or_request_with_http_token,我应该检查块内的令牌,如果块返回true,它应该通过。但是,即使我只是将 true 放入块中,该方法也永远不会通过。这是我在日志中看到的:

我正在使用导轨 4.0

  Filter chain halted as :restrict_access rendered or redirected
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

  before_filter :restrict_access

  def restrict_access
    authenticate_or_request_with_http_token do |token, options|
      true
    end
  end
Run Code Online (Sandbox Code Playgroud)

小智 5

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