Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Use HTTPX for oauth authorization state checks.

Pavel Balashouc22721c03a4b
diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb
index be177b34aff..c787eaa8543 100644
--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb
+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb
@@ -42,9 +42,9 @@ module Storages
def authorization_check_wrapper
case yield
- when Net::HTTPSuccess
+ when 200..299
:success
- when Net::HTTPForbidden, Net::HTTPUnauthorized
+ when 401, 403
:refresh_needed
else
:error
diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb
index 979005c1b0d..a977d630a8e 100644
--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb
+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb
@@ -44,16 +44,14 @@ module Storages
util = ::Storages::Peripherals::StorageInteraction::Nextcloud::Util
authorization_check_wrapper do
- Net::HTTP.start(@uri.host, @uri.port, use_ssl: true) do |http|
- http.get(
- util.join_uri_path(@uri.path, '/ocs/v1.php/cloud/user'),
- {
- 'Authorization' => "Bearer #{token}",
- 'OCS-APIRequest' => 'true',
- 'Accept' => 'application/json'
- }
- )
- end
+ HTTPX.get(
+ util.join_uri_path(@uri, '/ocs/v1.php/cloud/user'),
+ headers: {
+ 'Authorization' => "Bearer #{token}",
+ 'OCS-APIRequest' => 'true',
+ 'Accept' => 'application/json'
+ }
+ ).status
end
end
diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb
index 58e4514aa4e..781129cb833 100644
--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb
+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb
@@ -45,10 +45,13 @@ module Storages
end
def authorization_state_check(access_token)
+ util = ::Storages::Peripherals::StorageInteraction::OneDrive::Util
+
authorization_check_wrapper do
- Net::HTTP.start(@uri.host, @uri.port, use_ssl: true) do |http|
- http.get('/v1.0/me', { 'Authorization' => "Bearer #{access_token}", 'Accept' => 'application/json' })
- end
+ HTTPX.get(
+ util.join_uri_path(@uri, '/v1.0/me'),
+ headers: { 'Authorization' => "Bearer #{access_token}", 'Accept' => 'application/json' }
+ ).status
end
end
diff --git a/spec/requests/oauth_clients/ensure_connection_flow_spec.rb b/spec/requests/oauth_clients/ensure_connection_flow_spec.rb
index bcaea46d4c7..218e99886b4 100644
--- a/spec/requests/oauth_clients/ensure_connection_flow_spec.rb
+++ b/spec/requests/oauth_clients/ensure_connection_flow_spec.rb
@@ -125,10 +125,8 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :we
.with(
headers: {
'Accept' => 'application/json',
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization' => "Bearer #{oauth_client_token.access_token}",
'Ocs-Apirequest' => 'true',
- 'User-Agent' => 'Ruby'
}
).to_return(status: 200, body: "", headers: {})
end