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)
true
return ,但是每次调用这个 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