I have a grape-based API whose only clients are browser-based users who are already authenticated to my app through Devise. I was hoping to be able to take advantage of some of the devise controller helper methods like current_user, and also to return a 403 if there is no current authenticated user. Is there a reasonable way to do this?
I naively tried just importing the controller helper methods:
class API < Grape::API
prefix 'api'
format :json
include Devise::Controllers::Helpers
get 'hello' do
# would like to be able to use current_user here
{ result: 'hello' }
end
end
current_user and the other helper methods remain unavailable and throw undefined local variable or method 'current_user'.
Is there a way to take advantage of the authentication that devise has already done here and use that within my grape api methods?