From 5e154a767f087eeac6afb14b25b3b3038a15d912 Mon Sep 17 00:00:00 2001 From: Rob Zolkos Date: Wed, 8 Apr 2026 14:37:24 -0400 Subject: [PATCH] Allow bearer auth on Active Storage downloads --- app/controllers/concerns/authentication.rb | 6 +++++- lib/rails_ext/active_storage_authorization.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rb index a269fc2d6..95240f11e 100644 --- a/app/controllers/concerns/authentication.rb +++ b/app/controllers/concerns/authentication.rb @@ -57,7 +57,7 @@ module Authentication def authenticate_by_bearer_token if request.authorization.to_s.include?("Bearer") - if request.format.json? + if bearer_token_authenticatable_request? authenticate_or_request_with_http_token do |token| if identity = Identity.find_by_permissable_access_token(token, method: request.method) Current.identity = identity @@ -69,6 +69,10 @@ module Authentication end end + def bearer_token_authenticatable_request? + request.format.json? + end + def request_authentication if Current.account.present? session[:return_to_after_authenticating] = request.url diff --git a/lib/rails_ext/active_storage_authorization.rb b/lib/rails_ext/active_storage_authorization.rb index 7d6fa8510..33a2db43e 100644 --- a/lib/rails_ext/active_storage_authorization.rb +++ b/lib/rails_ext/active_storage_authorization.rb @@ -31,6 +31,10 @@ Rails.application.config.to_prepare do end private + def bearer_token_authenticatable_request? + true + end + def publicly_accessible_blob? @blob.publicly_accessible? end