Reputation: 1037
Im using http_basic method in Grape in my rails app, I have got it working but would like to provide a custom error if the authentication details are incorrect.
http_basic do |username, password|
@project = Project.where(api_key: username).first
end
This works but I cant seem to be able to throw a custom error if the project cannot be found
Upvotes: 2
Views: 272
Reputation: 471
http_basic do |username, password|
@project = Project.where(api_key: username).first
@project ? true : error!('Unauthorized. Invalid or expired token.', 401)
end
Don't forget to check that password is also valid :-)
Upvotes: 1