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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Incorporates feedback from @Kharonus
Marcello Rochaf7a40e64672d
diff --git a/app/services/oauth_clients/connection_manager.rb b/app/services/oauth_clients/connection_manager.rbindex 2ed9b21d9d6..a523134e421 100644--- a/app/services/oauth_clients/connection_manager.rb+++ b/app/services/oauth_clients/connection_manager.rb@@ -48,14 +48,14 @@ module OAuthClients# @param state (OAuth2 RFC) encapsulates the state of the calling page (URL + params) to return# @param scope (OAuth2 RFC) specifies the resources to access. Nextcloud only has one global scope.# @return ServiceResult with ServiceResult.result being either an OAuthClientToken or a redirection URL- def get_access_token(scope: [], state: nil)+ def get_access_token(state: nil)# Check for an already existing token from last calltoken = get_existing_tokenreturn ServiceResult.success(result: token) if token.present?# Return the Nextcloud OAuth authorization URI that a user needs to open to grant access and eventually obtain# a token.- @redirect_url = get_authorization_uri(scope:, state:)+ @redirect_url = get_authorization_uri(state:)ServiceResult.failure(result: @redirect_url)end@@ -88,10 +88,9 @@ module OAuthClients# @param state (OAuth2 RFC) is a nonce referencing a cookie containing the calling page (URL + params) to which to# return to at the end of the whole flow.# @param scope (OAuth2 RFC) specifies the resources to access. Nextcloud has only one global scope.- def get_authorization_uri(scope: [], state: nil)+ def get_authorization_uri(state: nil)client = rack_oauth_client # Configure and start the rack-oauth2 client- joined_scopes = @config.compute_scopes(scope)- client.authorization_uri(scope: joined_scopes, state:)+ client.authorization_uri(scope: @config.scope, state:)end# Called by callback_page with a cryptographic "code" that indicatesdiff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rbindex 0ddaf34b75c..be177b34aff 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@@ -34,7 +34,7 @@ module Storagesclass ConfigurationInterfacedef authorization_state_check(_) = raise ::Storages::Errors::SubclassResponsibility- def compute_scopes(_) = raise ::Storages::Errors::SubclassResponsibility+ def scope = raise ::Storages::Errors::SubclassResponsibilitydef basic_rack_oauth_client = raise ::Storages::Errors::SubclassResponsibilitydiff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rbindex af255a9743a..7e44f3888a7 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@@ -56,8 +56,8 @@ module Storagesendend- def compute_scopes(scopes)- scopes+ def scope+ []enddef basic_rack_oauth_clientdiff --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.rbindex c794ab764f2..e812f896e39 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@@ -51,8 +51,8 @@ module Storagesendend- def compute_scopes(scopes)- Array(scopes) | DEFAULT_SCOPES+ def scope+ DEFAULT_SCOPESenddef basic_rack_oauth_clientdiff --git a/spec/services/oauth_clients/connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_spec.rbindex cc7014961da..b0ed6dcfdd8 100644--- a/spec/services/oauth_clients/connection_manager_spec.rb+++ b/spec/services/oauth_clients/connection_manager_spec.rb@@ -49,7 +49,7 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true dolet(:scope) { nil }let(:state) { nil }- subject { instance.get_authorization_uri(scope:, state:) }+ subject { instance.get_authorization_uri(state:) }context 'with empty state and scope' doshared_examples_for 'returns the authorization URI relative to the host' do@@ -87,6 +87,8 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true dolet(:scope) { %i(email profile) }it 'returns the redirect URL' do+ allow(configuration).to receive(:scope).and_return(scope)+expect(subject).to be_a Stringexpect(subject).to include oauth_client.integration.hostexpect(subject).not_to include "state"@@ -110,9 +112,11 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true doendcontext 'with no OAuthClientToken present and state parameters' do- subject { instance.get_access_token(state: "some_state", scope: [:email]) }+ subject { instance.get_access_token(state: "some_state") }it 'returns the redirect URL' do+ allow(configuration).to receive(:scope).and_return(%w[email])+expect(subject.success).to be_falseyexpect(subject.result).to be_a Stringexpect(subject.result).to include oauth_client.integration.hostdiff --git a/spec/services/oauth_clients/one_drive_connection_manager_spec.rb b/spec/services/oauth_clients/one_drive_connection_manager_spec.rbindex 305d87c9df8..9a40f9f370b 100644--- a/spec/services/oauth_clients/one_drive_connection_manager_spec.rb+++ b/spec/services/oauth_clients/one_drive_connection_manager_spec.rb@@ -41,13 +41,13 @@ RSpec.describe OAuthClients::ConnectionManager, type: :model, webmock: true dodescribe '#get_authorization_uri' doit 'always add the necessary scopes' do- uri = connection_manager.get_authorization_uri(scope: nil, state: nil)+ uri = connection_manager.get_authorization_uri(state: nil)- expect(uri).to include storage.oauth_configuration.compute_scopes(nil).join('%20')+ expect(uri).to include storage.oauth_configuration.scope.join('%20')endit 'adds the state if present' do- uri = connection_manager.get_authorization_uri(scope: nil, state: 'https://some.site.com')+ uri = connection_manager.get_authorization_uri(state: 'https://some.site.com')expect(uri).to include "&state=https"endend