2

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

Sam Mason
  • 1,037
  • 1
  • 8
  • 29

1 Answers1

1
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 :-)

Jonny
  • 431
  • 4
  • 8