Assuming you didn't remove the "Reason" => "login needed" on purpose, I'd suggest this code
```ruby
authentication_scheme = if request.headers["X-ACCEPT-AUTH"] == "Session"
  'Session' else 'Basic'
end
format.any(:xml, :js, :json)  { head :unauthorized,
                                "Reason" => "login needed",
                                'WWW-Authenticate' => authentication_scheme + ' realm="OpenProject API"' }
```