我通过以下方式保护了以下API:
def restrict_access
authenticate_or_request_with_http_token do |token, options|
ApiKey.exists?(access_token: token)
end
end
以下卷曲有效:
curl --data "" http://localhost:3000/api/v1/leadapis -H 'Authorization: Token token="7bbb307792bac1588524003ac641fa55"'
然而在irb>
require 'rest-client'
RestClient.post('http://localhost:3000/api/v1/leadapis', '{}', 'authorization' => 'Token token = 7bbb307792bac1588524003ac641fa55')
curl和rest-client都在调试器中产生相同的request.authorization:
(rdb:18) request.authorization
"Token token = \"7bbb307792bac1588524003ac641fa55\""
任何帮助将不胜感激