Hi,
I'm trying to add Authentication to the api created as per example, but I can't find the way to send email and password in order to authenticate, it always responds "Unauthorized":
Using rocket_pants 1.13.0
app/controllers/api/v1/users_controller.rb
class Api::V1::UsersController < RocketPants::Base
include Devise::Controllers::Helpers
before_filter :authenticate_user!
version 1
def index
expose User.all # Not what we'd actually do, of course.
end
end
config/routes.rb
Hicatalogueenabler::Application.routes.draw do
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
resources :used_instances
root "pages#home"
get "home", to: "pages#home", as: "home"
get "inside", to: "pages#inside", as: "inside"
get "/contact", to: "pages#contact", as: "contact"
post "/emailconfirmation", to: "pages#email", as: "email_confirmation"
devise_for :users
# Rest API Rocket Pants
api versions: 1, module: "api/v1" do
resources :users, only: [:index]
end
end
This is the curl line I use for testing:
curl -i -X GET -d "user[email]=admin@example.com&user[password]=1234" 'http://localhost:3000/1/users'
The answer I get, from development.log is:
Started GET "/1/users" for 127.0.0.1 at 2015-08-04 03:12:31 +0200
Processing by Api::V1::UsersController#index as
Parameters: {"user"=>{"email"=>"admin@example.com", "password"=>"[FILTERED]"}, "version"=>"1"}
Completed 401 Unauthorized in 0ms
I tried even using CocoaRestClient in which I filled the HTTP Basic Auth or HTTP Digest Auth, but still I get:
Do I need to add something somewhere? Am I missing something in the request? I feel a bit lost, since there seems to be no clear documentation on the web about the integration between Rocket Pants and Devise, and how to use the integrated api...
Hi, I'm trying to add Authentication to the api created as per example, but I can't find the way to send email and password in order to authenticate, it always responds "Unauthorized":
Using rocket_pants 1.13.0
app/controllers/api/v1/users_controller.rb
config/routes.rb
This is the curl line I use for testing:
The answer I get, from development.log is:
I tried even using CocoaRestClient in which I filled the HTTP Basic Auth or HTTP Digest Auth, but still I get:
Do I need to add something somewhere? Am I missing something in the request? I feel a bit lost, since there seems to be no clear documentation on the web about the integration between Rocket Pants and Devise, and how to use the integrated api...
Thanks for the answer, Gabriele