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
Only accept access tokens of enabled OAuth applications
Jan Sandbrinka5986538e617
diff --git a/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rb b/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rbindex ac80d71effe..7c79e3d9b8e 100644--- a/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rb+++ b/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+require "doorkeeper/grape/authorization_decorator"module OpenProject@@ -12,10 +14,10 @@ module OpenProjectdef valid?access_token = ::Doorkeeper::OAuth::Token.from_request(decorated_request, *Doorkeeper.configuration.access_token_methods)-+# No access token found, so invalid strategy.return false if access_token.blank?-+# We don't want JWT as our OAuth Bearer tokenJWT.decode(access_token, nil, false)false@@ -28,6 +30,7 @@ module OpenProject*Doorkeeper.configuration.access_token_methods)return fail_with_header!(error: "invalid_token") if access_token.blank?return fail_with_header!(error: "invalid_token") if access_token.expired? || access_token.revoked?+ return fail_with_header!(error: "invalid_token") unless access_token.application.enabled?return fail_with_header!(error: "insufficient_scope") if !access_token.includes_scope?(scope)if access_token.resource_owner_id.nil?diff --git a/spec/requests/api/v3/authentication_spec.rb b/spec/requests/api/v3/authentication_spec.rbindex bea0b65d260..54c28cf2b26 100644--- a/spec/requests/api/v3/authentication_spec.rb+++ b/spec/requests/api/v3/authentication_spec.rb@@ -83,6 +83,17 @@ RSpec.describe "API V3 Authentication" doendend+ context "when the token's application is disabled" do+ let(:token) { create(:oauth_access_token, resource_owner: user, application: create(:oauth_application, enabled: false)) }+ let(:oauth_access_token) { token.plaintext_token }++ it "returns unauthorized" do+ expect(last_response).to have_http_status :unauthorized+ expect(last_response.header["WWW-Authenticate"]).to eq('Bearer realm="OpenProject API", error="invalid_token"')+ expect(JSON.parse(last_response.body)).to eq(error_response_body)+ end+ end+context "with an expired access token" dolet(:token) { create(:oauth_access_token, resource_owner: user) }let(:oauth_access_token) { token.plaintext_token }