A short snippet on how to make Ruby on Rails authenticate_or_request_with_http_basic respond with a JSON valid message upon failure.
class ApplicationController < ActionController::API
include(
ActionController::HttpAuthentication::Basic::ControllerMethods
)
before_action :http_authenticate!
def http_authenticate!
authenticate_or_request_with_http_basic do |key, secret|
return if Resource.find_by(
key: key,
secret: secret
)
end
render(
json: 'Invalid credentials'.to_json,
status: 401
)
end
end
Cover photo by Vladimer Shioshvili on Attribution-ShareAlike 2.0 Generic (CC BY-SA 2.0) license.
The post Ruby on Rails HTTP Basic authentication with JSON failure message appeared first on Running with Ruby.
This article demonstrates how to harden security of VPS server and is intended for server…
In this blog post, we will guide you on how to install wget on Ubuntu…
Jan 27,2026 Xfwl4 - The roadmap for a Xfce Wayland Compositor We, the Xfce team…
This article provides a step-by-step how-to guide to deploy n8n on Ubuntu VPS. What is…
In July 2025, git received CVE-2025-48384, a high vulnerability allowing arbitrary code execution when cloning…
Last year, we collaborated with two design student teams from Loughborough University in the UK.…