3
def restrict_access
  # raise ApiKey.exists?(access_token: params[:token]).to_s
  authenticate_or_request_with_http_token do |token, options|
    ApiKey.exists?(access_token: token)
  end
end

ApiKey.exists?(access_token: token)truereturn ,但是每次调用这个 def 时它都会返回 a ,HTTP Token: Access denied.我不知道为什么。我什至可以硬编码正确的令牌,但它仍然失败。它似乎只在开发和测试中这样做,但在产品中起作用,这让我感到害怕。它也刚刚开始发生,似乎是出乎意料的。我什至无法在 authenticate_or_request_with_http_token 块中调试任何东西,它甚至在 ApiKey.exists?() 被执行之前就把我踢了出去。

我已经查看了源代码,但这对我来说并不是那么有帮助。 https://github.com/rails/rails/blob/04cda1848cb847c2bdad0bfc12160dc8d5547775/actionpack/lib/action_controller/metal/http_authentication.rb#L393

4

1 回答 1

-1

文档中有一个注释,也许你有这个问题:

在共享主机上,Apache 有时不会将身份验证标头传递给 FCGI 实例。如果您的环境与此描述匹配并且您无法进行身份验证,请在您的 Apache 设置中尝试此规则:

RewriteRule ^(.*)$ dispatch.fcgi [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]

http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Token.html

于 2014-05-24T12:10:00.347 回答