diff --git a/app/contracts/oauth/applications/base_contract.rb b/app/contracts/oauth/applications/base_contract.rb index 2d54af5f4f94..68c66f0a383e 100644 --- a/app/contracts/oauth/applications/base_contract.rb +++ b/app/contracts/oauth/applications/base_contract.rb @@ -37,6 +37,7 @@ def self.model validate :validate_client_credential_user validate :validate_integration validate :validate_admin_only + validate :validate_internal_scopes attribute :enabled attribute :name @@ -57,6 +58,14 @@ def validate_admin_only errors.add :base, :error_unauthorized unless user.admin? end + def validate_internal_scopes + return if user.is_a?(SystemUser) || !model.will_save_change_to_scopes? + + if model.scopes.to_a.intersect?(OpenProject::Authentication.internal_oauth_scopes) + errors.add :scopes, :inclusion + end + end + def validate_integration both = model.integration_id.present? && model.integration_type.present? none = model.integration_id.nil? && model.integration_type.nil? diff --git a/app/controllers/oauth_metadata_controller.rb b/app/controllers/oauth_metadata_controller.rb index 283637a04f8c..3dd9cac6af4a 100644 --- a/app/controllers/oauth_metadata_controller.rb +++ b/app/controllers/oauth_metadata_controller.rb @@ -40,7 +40,7 @@ def authorization_server authorization_endpoint: oauth_authorization_url, token_endpoint: oauth_token_url, introspection_endpoint: oauth_introspect_url, - scopes_supported: Doorkeeper.configuration.scopes.to_a, + scopes_supported: supported_scopes, response_types_supported: response_types(Doorkeeper.configuration.grant_flows), grant_types_supported: grant_types, service_documentation: OpenProject::Static::Links.url_for(:oauth_applications) @@ -60,6 +60,10 @@ def protected_resource private + def supported_scopes + Doorkeeper.configuration.scopes.to_a - OpenProject::Authentication.internal_oauth_scopes + end + def response_types(grant_types) grant_types.filter_map do |grant| case grant diff --git a/app/views/oauth/applications/_form.html.erb b/app/views/oauth/applications/_form.html.erb index 9f9e5a27d804..a56cd84e2cd0 100644 --- a/app/views/oauth/applications/_form.html.erb +++ b/app/views/oauth/applications/_form.html.erb @@ -51,10 +51,11 @@ See COPYRIGHT and LICENSE files for more details. - <% if Doorkeeper.configuration.scopes.all.length > 1 %> + <% selectable_scopes = Doorkeeper.configuration.scopes.to_a - OpenProject::Authentication.internal_oauth_scopes %> + <% if selectable_scopes.length > 1 %>
- <% Doorkeeper.configuration.scopes.each do |scope| %> + <% selectable_scopes.each do |scope| %>