Development and authentication with CURL!

I would like to be able to authenticate through curl!

So, I would like to get a token on login:

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 get:

 {"email":" em...@provider.us ","name":"Name of the user"} 

How can I add some specific fields like authentication_token?

I want me to be right? Is there any other better way to do this?

Thanks!

+1
source share
1 answer

I created a controller called 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 :-)

+3
source

Source: https://habr.com/ru/post/1379493/


All Articles