Closed
Description
As part of the authentication scheme for my API, the URL the consumer accessed is hashed as part of an authentication token. However, when I access request.url
in my authentication code, the API prefix and the API version specified are not reflected in the URL:
class API < Grape::API
error_format :json
use API::Auth, :token_class => "ApiToken"
version 'v1', :using => :path
prefix 'api'
resources :employees do
get do
Employee.all
end
end
end
If I GET /api/v1/employees.json
, request.url
is set to http://www.example.com//employees
(note the double slash). Since the consumer, however, is (properly) using http://www.example.com/api/v1/employees
as the URL, the URL on each side does not match up and authentication fails.
Any ideas how to fix or get around this?