I would like to be able to authenticate through a curl style !
So I would like to get a Token when I signed in :
curl -X POST 'http://localhost:3000/users/sign_in.json' -d 'user[email]=em...@provider.us&user[password]=pass'
But if I perform this action I only get :
{"email":"em...@provider.us","name":"Name of the user"}
开发者_运维百科How I could add some specific fields like authentication_token ?
Is what I want to do is right ? Is there any other better way to do this ?
Thanks !
I created a Controller named SessionController
class Users::SessionsController < Devise::SessionsController
append_view_path 'app/views/devise'
def create
respond_to do |format|
format.html { super }
format.json {
warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
current_user.ensure_authentication_token!
render :json => {:user => current_user.api_attributes, :auth_token => current_user.authentication_token}.to_json, :status => :ok
}
end
end
def destroy
respond_to do |format|
format.html { super }
format.json {
warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
current_user.empty_authentication_token!
render :json => {}.to_json, :status => :ok
}
end
end
end
And added this to the root file :
devise_for :users, :controllers => { :sessions => "users/sessions" }
And it works :-)
精彩评论