OK - 302 + Location
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled

This commit is contained in:
Dan Milne
2025-10-23 23:52:01 +11:00
parent e3e2a565e7
commit 7200a6735f

View File

@@ -131,12 +131,22 @@ module Api
"https://#{request.headers['Host']}"
end
# Debug: log what we're redirecting to after login
Rails.logger.info "ForwardAuth: Will redirect to after login: #{original_url}"
session[:return_to_after_authenticating] = original_url
# Return 401 Unauthorized with Location header
# Caddy will automatically redirect to this URL
response.headers["Location"] = "#{base_url}/signin"
head :unauthorized
# Build login URL with redirect parameters like Authelia
login_url = URI.parse("#{base_url}/signin")
login_url.query_params = {
rd: original_url,
rm: request.method
}.to_query
# Return 302 Found directly to login page (matching Authelia)
# This is the same as Authelia's StatusFound response
Rails.logger.info "Setting 302 redirect to: #{login_url}"
redirect_to login_url.to_s, allow_other_host: true, status: :found
end
def render_forbidden(reason = nil)