I am using the Grape gem to create an API for my application. Everything worked fine until I added http authentication to my api, which is built into Appe Grape.
Here is the code I have:
require 'grape' module MyApp class API < Grape::API prefix 'api' version 'v1' helpers do def current_user @current_user ||= User.authenticate(env) end def authenticate! error!('401 Unauthorized', 401) unless current_user end end resources :projects do http_basic do |u,p| authenticate!
It seems that I canβt access any methods or objects inside the http_basic block, including the request, env, anything in the helper methods and even an error!
Having a look at the code, this makes no sense.
Has anyone come across this before? Does anyone have any examples of using the Grape API with basic HTTP authentication? Examples on the Internet are not real world examples.
source share