If token auth just isn't what you want to do, you can also return a cookie and have the client include the cookie in the request header. It works very similar to the web sessions controller.
In an API sessions controller
class Api::V1::SessionsController < Devise::SessionsController
skip_before_action :authenticate_user!
skip_before_action :verify_authenticity_token
def create
warden.authenticate!(:scope => :user)
render :json => current_user
end
end
In Routes
namespace :api, :defaults => { :format => 'json' } do
namespace :v1 do
resource :account, :only => :show
devise_scope :user do
post :sessions, :to => 'sessions#create'
delete :session, :to => 'sessions#destroy'
end
end
end
Then you can do this sort of thing (examples are using HTTPie)
http -f POST localhost:3000/api/v1/sessions user[email]=user@email.com user[password]=passw0rd
The response headers will have a session in the Set-Cookie header. Put the value of this in subsequent requests.
http localhost:3000/api/v1/restricted_things/1 'Cookie:_my_site_session=<sessionstring>; path=/; HttpOnly'