doorkeeper 5.4.0.rc1 → 5.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +108 -9
- data/README.md +4 -4
- data/app/controllers/doorkeeper/applications_controller.rb +3 -3
- data/app/controllers/doorkeeper/authorizations_controller.rb +16 -5
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/token_info_controller.rb +12 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +34 -26
- data/app/views/doorkeeper/applications/_form.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +16 -12
- data/app/views/doorkeeper/authorizations/form_post.html.erb +11 -0
- data/config/locales/en.yml +3 -1
- data/lib/doorkeeper.rb +6 -1
- data/lib/doorkeeper/config.rb +109 -78
- data/lib/doorkeeper/config/abstract_builder.rb +1 -1
- data/lib/doorkeeper/config/option.rb +1 -3
- data/lib/doorkeeper/config/validations.rb +53 -0
- data/lib/doorkeeper/engine.rb +1 -1
- data/lib/doorkeeper/grant_flow.rb +45 -0
- data/lib/doorkeeper/grant_flow/fallback_flow.rb +15 -0
- data/lib/doorkeeper/grant_flow/flow.rb +44 -0
- data/lib/doorkeeper/grant_flow/registry.rb +50 -0
- data/lib/doorkeeper/helpers/controller.rb +8 -4
- data/lib/doorkeeper/models/access_grant_mixin.rb +12 -7
- data/lib/doorkeeper/models/access_token_mixin.rb +12 -8
- data/lib/doorkeeper/models/application_mixin.rb +5 -4
- data/lib/doorkeeper/models/concerns/revocable.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/code.rb +5 -1
- data/lib/doorkeeper/oauth/authorization/context.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/token.rb +11 -5
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_code_request.rb +10 -17
- data/lib/doorkeeper/oauth/base_request.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +3 -2
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +1 -0
- data/lib/doorkeeper/oauth/client_credentials/validator.rb +3 -1
- data/lib/doorkeeper/oauth/code_request.rb +2 -2
- data/lib/doorkeeper/oauth/code_response.rb +17 -11
- data/lib/doorkeeper/oauth/error_response.rb +4 -3
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -3
- data/lib/doorkeeper/oauth/password_access_token_request.rb +21 -2
- data/lib/doorkeeper/oauth/pre_authorization.rb +37 -11
- data/lib/doorkeeper/oauth/refresh_token_request.rb +13 -0
- data/lib/doorkeeper/oauth/token.rb +4 -5
- data/lib/doorkeeper/oauth/token_introspection.rb +1 -5
- data/lib/doorkeeper/oauth/token_request.rb +1 -1
- data/lib/doorkeeper/orm/active_record.rb +5 -6
- data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +12 -2
- data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +10 -2
- data/lib/doorkeeper/orm/active_record/mixins/application.rb +76 -10
- data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +5 -0
- data/lib/doorkeeper/rails/routes.rb +1 -3
- data/lib/doorkeeper/rake/db.rake +3 -3
- data/lib/doorkeeper/rake/setup.rake +5 -0
- data/lib/doorkeeper/request.rb +49 -12
- data/lib/doorkeeper/request/refresh_token.rb +2 -1
- data/lib/doorkeeper/server.rb +1 -1
- data/lib/doorkeeper/stale_records_cleaner.rb +4 -4
- data/lib/doorkeeper/version.rb +2 -6
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb +1 -1
- data/lib/generators/doorkeeper/templates/initializer.rb +9 -7
- data/lib/generators/doorkeeper/templates/migration.rb.erb +12 -5
- metadata +25 -306
- data/Appraisals +0 -26
- data/CODE_OF_CONDUCT.md +0 -46
- data/CONTRIBUTING.md +0 -49
- data/Dangerfile +0 -67
- data/Dockerfile +0 -29
- data/Gemfile +0 -25
- data/NEWS.md +0 -1
- data/RELEASING.md +0 -11
- data/Rakefile +0 -28
- data/SECURITY.md +0 -15
- data/UPGRADE.md +0 -2
- data/bin/console +0 -30
- data/doorkeeper.gemspec +0 -42
- data/gemfiles/rails_5_0.gemfile +0 -19
- data/gemfiles/rails_5_1.gemfile +0 -19
- data/gemfiles/rails_5_2.gemfile +0 -19
- data/gemfiles/rails_6_0.gemfile +0 -19
- data/gemfiles/rails_master.gemfile +0 -19
- data/spec/controllers/application_metal_controller_spec.rb +0 -64
- data/spec/controllers/applications_controller_spec.rb +0 -274
- data/spec/controllers/authorizations_controller_spec.rb +0 -743
- data/spec/controllers/protected_resources_controller_spec.rb +0 -361
- data/spec/controllers/token_info_controller_spec.rb +0 -50
- data/spec/controllers/tokens_controller_spec.rb +0 -499
- data/spec/dummy/Rakefile +0 -9
- data/spec/dummy/app/assets/config/manifest.js +0 -2
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -9
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -14
- data/spec/dummy/app/controllers/home_controller.rb +0 -18
- data/spec/dummy/app/controllers/metal_controller.rb +0 -13
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -13
- data/spec/dummy/app/helpers/application_helper.rb +0 -7
- data/spec/dummy/app/models/user.rb +0 -11
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config.ru +0 -6
- data/spec/dummy/config/application.rb +0 -51
- data/spec/dummy/config/boot.rb +0 -7
- data/spec/dummy/config/database.yml +0 -15
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -31
- data/spec/dummy/config/environments/production.rb +0 -64
- data/spec/dummy/config/environments/test.rb +0 -45
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -9
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -166
- data/spec/dummy/config/initializers/secret_token.rb +0 -10
- data/spec/dummy/config/initializers/session_store.rb +0 -10
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -16
- data/spec/dummy/config/locales/doorkeeper.en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -13
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -11
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -7
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -69
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -9
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -13
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -8
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -13
- data/spec/dummy/db/schema.rb +0 -70
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -26
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -9
- data/spec/factories.rb +0 -30
- data/spec/generators/application_owner_generator_spec.rb +0 -28
- data/spec/generators/confidential_applications_generator_spec.rb +0 -29
- data/spec/generators/enable_polymorphic_resource_owner_generator_spec.rb +0 -47
- data/spec/generators/install_generator_spec.rb +0 -36
- data/spec/generators/migration_generator_spec.rb +0 -28
- data/spec/generators/pkce_generator_spec.rb +0 -28
- data/spec/generators/previous_refresh_token_generator_spec.rb +0 -44
- data/spec/generators/templates/routes.rb +0 -4
- data/spec/generators/views_generator_spec.rb +0 -29
- data/spec/grape/grape_integration_spec.rb +0 -137
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +0 -26
- data/spec/lib/config_spec.rb +0 -813
- data/spec/lib/doorkeeper_spec.rb +0 -27
- data/spec/lib/models/expirable_spec.rb +0 -61
- data/spec/lib/models/reusable_spec.rb +0 -40
- data/spec/lib/models/revocable_spec.rb +0 -58
- data/spec/lib/models/scopes_spec.rb +0 -61
- data/spec/lib/models/secret_storable_spec.rb +0 -135
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -39
- data/spec/lib/oauth/authorization_code_request_spec.rb +0 -180
- data/spec/lib/oauth/base_request_spec.rb +0 -210
- data/spec/lib/oauth/base_response_spec.rb +0 -45
- data/spec/lib/oauth/client/credentials_spec.rb +0 -90
- data/spec/lib/oauth/client_credentials/creator_spec.rb +0 -135
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -110
- data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -57
- data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -27
- data/spec/lib/oauth/client_credentials_request_spec.rb +0 -108
- data/spec/lib/oauth/client_spec.rb +0 -38
- data/spec/lib/oauth/code_request_spec.rb +0 -46
- data/spec/lib/oauth/code_response_spec.rb +0 -36
- data/spec/lib/oauth/error_response_spec.rb +0 -64
- data/spec/lib/oauth/error_spec.rb +0 -21
- data/spec/lib/oauth/forbidden_token_response_spec.rb +0 -20
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -110
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -21
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +0 -262
- data/spec/lib/oauth/invalid_request_response_spec.rb +0 -73
- data/spec/lib/oauth/invalid_token_response_spec.rb +0 -53
- data/spec/lib/oauth/password_access_token_request_spec.rb +0 -201
- data/spec/lib/oauth/pre_authorization_spec.rb +0 -218
- data/spec/lib/oauth/refresh_token_request_spec.rb +0 -166
- data/spec/lib/oauth/scopes_spec.rb +0 -146
- data/spec/lib/oauth/token_request_spec.rb +0 -164
- data/spec/lib/oauth/token_response_spec.rb +0 -84
- data/spec/lib/oauth/token_spec.rb +0 -156
- data/spec/lib/option_spec.rb +0 -51
- data/spec/lib/request/strategy_spec.rb +0 -54
- data/spec/lib/secret_storing/base_spec.rb +0 -60
- data/spec/lib/secret_storing/bcrypt_spec.rb +0 -49
- data/spec/lib/secret_storing/plain_spec.rb +0 -44
- data/spec/lib/secret_storing/sha256_hash_spec.rb +0 -48
- data/spec/lib/server_spec.rb +0 -49
- data/spec/lib/stale_records_cleaner_spec.rb +0 -102
- data/spec/models/doorkeeper/access_grant_spec.rb +0 -175
- data/spec/models/doorkeeper/access_token_spec.rb +0 -650
- data/spec/models/doorkeeper/application_spec.rb +0 -442
- data/spec/requests/applications/applications_request_spec.rb +0 -259
- data/spec/requests/applications/authorized_applications_spec.rb +0 -32
- data/spec/requests/endpoints/authorization_spec.rb +0 -91
- data/spec/requests/endpoints/token_spec.rb +0 -79
- data/spec/requests/flows/authorization_code_errors_spec.rb +0 -82
- data/spec/requests/flows/authorization_code_spec.rb +0 -530
- data/spec/requests/flows/client_credentials_spec.rb +0 -207
- data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -46
- data/spec/requests/flows/implicit_grant_spec.rb +0 -91
- data/spec/requests/flows/password_spec.rb +0 -316
- data/spec/requests/flows/refresh_token_spec.rb +0 -241
- data/spec/requests/flows/revoke_token_spec.rb +0 -196
- data/spec/requests/flows/skip_authorization_spec.rb +0 -66
- data/spec/requests/protected_resources/metal_spec.rb +0 -16
- data/spec/requests/protected_resources/private_api_spec.rb +0 -83
- data/spec/routing/custom_controller_routes_spec.rb +0 -133
- data/spec/routing/default_routes_spec.rb +0 -41
- data/spec/routing/scoped_routes_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -54
- data/spec/spec_helper_integration.rb +0 -4
- data/spec/support/dependencies/factory_bot.rb +0 -4
- data/spec/support/doorkeeper_rspec.rb +0 -22
- data/spec/support/helpers/access_token_request_helper.rb +0 -14
- data/spec/support/helpers/authorization_request_helper.rb +0 -43
- data/spec/support/helpers/config_helper.rb +0 -11
- data/spec/support/helpers/model_helper.rb +0 -78
- data/spec/support/helpers/request_spec_helper.rb +0 -110
- data/spec/support/helpers/url_helper.rb +0 -62
- data/spec/support/orm/active_record.rb +0 -5
- data/spec/support/shared/controllers_shared_context.rb +0 -133
- data/spec/support/shared/hashing_shared_context.rb +0 -36
- data/spec/support/shared/models_shared_examples.rb +0 -56
- data/spec/validators/redirect_uri_validator_spec.rb +0 -183
- data/spec/version/version_spec.rb +0 -17
data/lib/doorkeeper.rb
CHANGED
@@ -6,8 +6,9 @@ require "doorkeeper/engine"
|
|
6
6
|
# Main Doorkeeper namespace.
|
7
7
|
#
|
8
8
|
module Doorkeeper
|
9
|
-
autoload :OAuth, "doorkeeper/oauth"
|
10
9
|
autoload :Errors, "doorkeeper/errors"
|
10
|
+
autoload :GrantFlow, "doorkeeper/grant_flow"
|
11
|
+
autoload :OAuth, "doorkeeper/oauth"
|
11
12
|
autoload :Rake, "doorkeeper/rake"
|
12
13
|
autoload :Request, "doorkeeper/request"
|
13
14
|
autoload :Server, "doorkeeper/server"
|
@@ -114,4 +115,8 @@ module Doorkeeper
|
|
114
115
|
def self.authenticate(request, methods = Doorkeeper.config.access_token_methods)
|
115
116
|
OAuth::Token.authenticate(request, *methods)
|
116
117
|
end
|
118
|
+
|
119
|
+
def self.gem_version
|
120
|
+
::Gem::Version.new(::Doorkeeper::VERSION::STRING)
|
121
|
+
end
|
117
122
|
end
|
data/lib/doorkeeper/config.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "doorkeeper/config/option"
|
4
3
|
require "doorkeeper/config/abstract_builder"
|
4
|
+
require "doorkeeper/config/option"
|
5
|
+
require "doorkeeper/config/validations"
|
5
6
|
|
6
7
|
module Doorkeeper
|
7
8
|
# Defines a MissingConfiguration error for a missing Doorkeeper configuration
|
@@ -28,6 +29,8 @@ module Doorkeeper
|
|
28
29
|
@config
|
29
30
|
end
|
30
31
|
|
32
|
+
# @return [Doorkeeper::Config] configuration instance
|
33
|
+
#
|
31
34
|
def configuration
|
32
35
|
@config || (raise MissingConfiguration)
|
33
36
|
end
|
@@ -134,15 +137,6 @@ module Doorkeeper
|
|
134
137
|
@config.instance_variable_set(:@reuse_access_token, true)
|
135
138
|
end
|
136
139
|
|
137
|
-
# Sets the token_reuse_limit
|
138
|
-
# It will be used only when reuse_access_token option in enabled
|
139
|
-
# By default it will be 100
|
140
|
-
# It will be used for token reusablity to some threshold percentage
|
141
|
-
# Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/1189
|
142
|
-
def token_reuse_limit(percentage)
|
143
|
-
@config.instance_variable_set(:@token_reuse_limit, percentage)
|
144
|
-
end
|
145
|
-
|
146
140
|
# TODO: maybe make it more generic for other flows too?
|
147
141
|
# Only allow one valid access token obtained via client credentials
|
148
142
|
# per client. If a new access token is obtained before the old one
|
@@ -228,6 +222,7 @@ module Doorkeeper
|
|
228
222
|
mattr_reader(:builder_class) { Builder }
|
229
223
|
|
230
224
|
extend Option
|
225
|
+
include Validations
|
231
226
|
|
232
227
|
option :resource_owner_authenticator,
|
233
228
|
as: :authenticate_resource_owner,
|
@@ -276,6 +271,23 @@ module Doorkeeper
|
|
276
271
|
option :grant_flows, default: %w[authorization_code client_credentials]
|
277
272
|
option :handle_auth_errors, default: :render
|
278
273
|
option :token_lookup_batch_size, default: 10_000
|
274
|
+
# Sets the token_reuse_limit
|
275
|
+
# It will be used only when reuse_access_token option in enabled
|
276
|
+
# By default it will be 100
|
277
|
+
# It will be used for token reusablity to some threshold percentage
|
278
|
+
# Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/1189
|
279
|
+
option :token_reuse_limit, default: 100
|
280
|
+
|
281
|
+
# This is discouraged. Spec says that password grants always require a client.
|
282
|
+
#
|
283
|
+
# See https://github.com/doorkeeper-gem/doorkeeper/issues/1412#issuecomment-632750422
|
284
|
+
# and https://github.com/doorkeeper-gem/doorkeeper/pull/1420
|
285
|
+
#
|
286
|
+
# Since many applications use this unsafe behavior in the wild, this is kept as a
|
287
|
+
# not-recommended option. You should be aware that you are not following the OAuth
|
288
|
+
# spec, and understand the security implications of doing so.
|
289
|
+
option :skip_client_authentication_for_password_grant,
|
290
|
+
default: false
|
279
291
|
|
280
292
|
option :active_record_options,
|
281
293
|
default: {},
|
@@ -425,21 +437,26 @@ module Doorkeeper
|
|
425
437
|
:token_secret_fallback_strategy,
|
426
438
|
:application_secret_fallback_strategy
|
427
439
|
|
428
|
-
#
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
validate_secret_strategies
|
433
|
-
end
|
434
|
-
|
440
|
+
# Doorkeeper Access Token model class.
|
441
|
+
#
|
442
|
+
# @return [ActiveRecord::Base, Mongoid::Document, Sequel::Model]
|
443
|
+
#
|
435
444
|
def access_token_model
|
436
445
|
@access_token_model ||= access_token_class.constantize
|
437
446
|
end
|
438
447
|
|
448
|
+
# Doorkeeper Access Grant model class.
|
449
|
+
#
|
450
|
+
# @return [ActiveRecord::Base, Mongoid::Document, Sequel::Model]
|
451
|
+
#
|
439
452
|
def access_grant_model
|
440
453
|
@access_grant_model ||= access_grant_class.constantize
|
441
454
|
end
|
442
455
|
|
456
|
+
# Doorkeeper Application model class.
|
457
|
+
#
|
458
|
+
# @return [ActiveRecord::Base, Mongoid::Document, Sequel::Model]
|
459
|
+
#
|
443
460
|
def application_model
|
444
461
|
@application_model ||= application_class.constantize
|
445
462
|
end
|
@@ -460,14 +477,6 @@ module Doorkeeper
|
|
460
477
|
end
|
461
478
|
end
|
462
479
|
|
463
|
-
def token_reuse_limit
|
464
|
-
@token_reuse_limit ||= 100
|
465
|
-
end
|
466
|
-
|
467
|
-
def revoke_previous_client_credentials_token
|
468
|
-
@revoke_previous_client_credentials_token || false
|
469
|
-
end
|
470
|
-
|
471
480
|
def resolve_controller(name)
|
472
481
|
config_option = public_send(:"#{name}_controller")
|
473
482
|
controller_name = if config_option.respond_to?(:call)
|
@@ -479,6 +488,10 @@ module Doorkeeper
|
|
479
488
|
controller_name.constantize
|
480
489
|
end
|
481
490
|
|
491
|
+
def revoke_previous_client_credentials_token?
|
492
|
+
option_set? :revoke_previous_client_credentials_token
|
493
|
+
end
|
494
|
+
|
482
495
|
def enforce_configured_scopes?
|
483
496
|
option_set? :enforce_configured_scopes
|
484
497
|
end
|
@@ -539,12 +552,77 @@ module Doorkeeper
|
|
539
552
|
]
|
540
553
|
end
|
541
554
|
|
555
|
+
def enabled_grant_flows
|
556
|
+
@enabled_grant_flows ||= calculate_grant_flows.map { |name| Doorkeeper::GrantFlow.get(name) }.compact
|
557
|
+
end
|
558
|
+
|
559
|
+
def authorization_response_flows
|
560
|
+
@authorization_response_flows ||= enabled_grant_flows.select(&:handles_response_type?) +
|
561
|
+
deprecated_authorization_flows
|
562
|
+
end
|
563
|
+
|
564
|
+
def token_grant_flows
|
565
|
+
@token_grant_flows ||= calculate_token_grant_flows
|
566
|
+
end
|
567
|
+
|
542
568
|
def authorization_response_types
|
543
|
-
|
569
|
+
authorization_response_flows.map(&:response_type_matches)
|
544
570
|
end
|
545
571
|
|
546
572
|
def token_grant_types
|
547
|
-
|
573
|
+
token_grant_flows.map(&:grant_type_matches)
|
574
|
+
end
|
575
|
+
|
576
|
+
# [NOTE]: deprecated and will be removed soon
|
577
|
+
def deprecated_token_grant_types_resolver
|
578
|
+
@deprecated_token_grant_types ||= calculate_token_grant_types
|
579
|
+
end
|
580
|
+
|
581
|
+
# [NOTE]: deprecated and will be removed soon
|
582
|
+
def deprecated_authorization_flows
|
583
|
+
response_types = calculate_authorization_response_types
|
584
|
+
|
585
|
+
if response_types.any?
|
586
|
+
::Kernel.warn <<~WARNING
|
587
|
+
Please, don't patch Doorkeeper::Config#calculate_authorization_response_types method.
|
588
|
+
Register your custom grant flows using the public API:
|
589
|
+
`Doorkeeper::GrantFlow.register(grant_flow_name, **options)`.
|
590
|
+
WARNING
|
591
|
+
end
|
592
|
+
|
593
|
+
response_types.map do |response_type|
|
594
|
+
Doorkeeper::GrantFlow::FallbackFlow.new(response_type, response_type_matches: response_type)
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
# [NOTE]: deprecated and will be removed soon
|
599
|
+
def calculate_authorization_response_types
|
600
|
+
[]
|
601
|
+
end
|
602
|
+
|
603
|
+
# [NOTE]: deprecated and will be removed soon
|
604
|
+
def calculate_token_grant_types
|
605
|
+
types = grant_flows - ["implicit"]
|
606
|
+
types << "refresh_token" if refresh_token_enabled?
|
607
|
+
types
|
608
|
+
end
|
609
|
+
|
610
|
+
# Calculates grant flows configured by the user in Doorkeeper
|
611
|
+
# configuration considering registered aliases that is exposed
|
612
|
+
# to single or multiple other flows.
|
613
|
+
#
|
614
|
+
def calculate_grant_flows
|
615
|
+
configured_flows = grant_flows.map(&:to_s)
|
616
|
+
aliases = Doorkeeper::GrantFlow.aliases.keys.map(&:to_s)
|
617
|
+
|
618
|
+
flows = configured_flows - aliases
|
619
|
+
aliases.each do |flow_alias|
|
620
|
+
next unless configured_flows.include?(flow_alias)
|
621
|
+
|
622
|
+
flows.concat(Doorkeeper::GrantFlow.expand_alias(flow_alias))
|
623
|
+
end
|
624
|
+
|
625
|
+
flows.flatten.uniq
|
548
626
|
end
|
549
627
|
|
550
628
|
def allow_blank_redirect_uri?(application = nil)
|
@@ -573,57 +651,10 @@ module Doorkeeper
|
|
573
651
|
!!(defined?(var) && var)
|
574
652
|
end
|
575
653
|
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
types = []
|
581
|
-
types << "code" if grant_flows.include? "authorization_code"
|
582
|
-
types << "token" if grant_flows.include? "implicit"
|
583
|
-
types
|
584
|
-
end
|
585
|
-
|
586
|
-
# Determines what values are acceptable for 'grant_type' param token
|
587
|
-
# request endpoint, and return them in array.
|
588
|
-
#
|
589
|
-
def calculate_token_grant_types
|
590
|
-
types = grant_flows - ["implicit"]
|
591
|
-
types << "refresh_token" if refresh_token_enabled?
|
592
|
-
types
|
593
|
-
end
|
594
|
-
|
595
|
-
# Determine whether +reuse_access_token+ and a non-restorable
|
596
|
-
# +token_secret_strategy+ have both been activated.
|
597
|
-
#
|
598
|
-
# In that case, disable reuse_access_token value and warn the user.
|
599
|
-
def validate_reuse_access_token_value
|
600
|
-
strategy = token_secret_strategy
|
601
|
-
return if !reuse_access_token || strategy.allows_restoring_secrets?
|
602
|
-
|
603
|
-
::Rails.logger.warn(
|
604
|
-
"You have configured both reuse_access_token " \
|
605
|
-
"AND strategy strategy '#{strategy}' that cannot restore tokens. " \
|
606
|
-
"This combination is unsupported. reuse_access_token will be disabled",
|
607
|
-
)
|
608
|
-
@reuse_access_token = false
|
609
|
-
end
|
610
|
-
|
611
|
-
# Validate that the provided strategies are valid for
|
612
|
-
# tokens and applications
|
613
|
-
def validate_secret_strategies
|
614
|
-
token_secret_strategy.validate_for :token
|
615
|
-
application_secret_strategy.validate_for :application
|
616
|
-
end
|
617
|
-
|
618
|
-
def validate_token_reuse_limit
|
619
|
-
return if !reuse_access_token ||
|
620
|
-
(token_reuse_limit > 0 && token_reuse_limit <= 100)
|
621
|
-
|
622
|
-
::Rails.logger.warn(
|
623
|
-
"You have configured an invalid value for token_reuse_limit option. " \
|
624
|
-
"It will be set to default 100",
|
625
|
-
)
|
626
|
-
@token_reuse_limit = 100
|
654
|
+
def calculate_token_grant_flows
|
655
|
+
flows = enabled_grant_flows.select(&:handles_grant_type?)
|
656
|
+
flows << Doorkeeper::GrantFlow.get("refresh_token") if refresh_token_enabled?
|
657
|
+
flows
|
627
658
|
end
|
628
659
|
end
|
629
660
|
end
|
@@ -45,9 +45,7 @@ module Doorkeeper
|
|
45
45
|
define_method name do |*args, &block|
|
46
46
|
if (deprecation_opts = options[:deprecated])
|
47
47
|
warning = "[DOORKEEPER] #{name} has been deprecated and will soon be removed"
|
48
|
-
if deprecation_opts.is_a?(Hash)
|
49
|
-
warning = "#{warning}\n#{deprecation_opts.fetch(:message)}"
|
50
|
-
end
|
48
|
+
warning = "#{warning}\n#{deprecation_opts.fetch(:message)}" if deprecation_opts.is_a?(Hash)
|
51
49
|
|
52
50
|
Kernel.warn(warning)
|
53
51
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Doorkeeper
|
4
|
+
class Config
|
5
|
+
# Doorkeeper configuration validator.
|
6
|
+
#
|
7
|
+
module Validations
|
8
|
+
# Validates configuration options to be set properly.
|
9
|
+
#
|
10
|
+
def validate!
|
11
|
+
validate_reuse_access_token_value
|
12
|
+
validate_token_reuse_limit
|
13
|
+
validate_secret_strategies
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# Determine whether +reuse_access_token+ and a non-restorable
|
19
|
+
# +token_secret_strategy+ have both been activated.
|
20
|
+
#
|
21
|
+
# In that case, disable reuse_access_token value and warn the user.
|
22
|
+
def validate_reuse_access_token_value
|
23
|
+
strategy = token_secret_strategy
|
24
|
+
return if !reuse_access_token || strategy.allows_restoring_secrets?
|
25
|
+
|
26
|
+
::Rails.logger.warn(
|
27
|
+
"You have configured both reuse_access_token " \
|
28
|
+
"AND strategy strategy '#{strategy}' that cannot restore tokens. " \
|
29
|
+
"This combination is unsupported. reuse_access_token will be disabled",
|
30
|
+
)
|
31
|
+
@reuse_access_token = false
|
32
|
+
end
|
33
|
+
|
34
|
+
# Validate that the provided strategies are valid for
|
35
|
+
# tokens and applications
|
36
|
+
def validate_secret_strategies
|
37
|
+
token_secret_strategy.validate_for(:token)
|
38
|
+
application_secret_strategy.validate_for(:application)
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate_token_reuse_limit
|
42
|
+
return if !reuse_access_token ||
|
43
|
+
(token_reuse_limit > 0 && token_reuse_limit <= 100)
|
44
|
+
|
45
|
+
::Rails.logger.warn(
|
46
|
+
"You have configured an invalid value for token_reuse_limit option. " \
|
47
|
+
"It will be set to default 100",
|
48
|
+
)
|
49
|
+
@token_reuse_limit = 100
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/doorkeeper/engine.rb
CHANGED
@@ -4,7 +4,7 @@ module Doorkeeper
|
|
4
4
|
class Engine < Rails::Engine
|
5
5
|
initializer "doorkeeper.params.filter" do |app|
|
6
6
|
parameters = %w[client_secret code authentication_token access_token refresh_token]
|
7
|
-
app.config.filter_parameters << /^(#{Regexp.union
|
7
|
+
app.config.filter_parameters << /^(#{Regexp.union(parameters)})$/
|
8
8
|
end
|
9
9
|
|
10
10
|
initializer "doorkeeper.routes" do
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "doorkeeper/grant_flow/flow"
|
4
|
+
require "doorkeeper/grant_flow/fallback_flow"
|
5
|
+
require "doorkeeper/grant_flow/registry"
|
6
|
+
|
7
|
+
module Doorkeeper
|
8
|
+
module GrantFlow
|
9
|
+
extend Registry
|
10
|
+
|
11
|
+
register(
|
12
|
+
:implicit,
|
13
|
+
response_type_matches: "token",
|
14
|
+
response_mode_matches: %w[fragment form_post],
|
15
|
+
response_type_strategy: Doorkeeper::Request::Token,
|
16
|
+
)
|
17
|
+
|
18
|
+
register(
|
19
|
+
:authorization_code,
|
20
|
+
response_type_matches: "code",
|
21
|
+
response_mode_matches: %w[query fragment form_post],
|
22
|
+
response_type_strategy: Doorkeeper::Request::Code,
|
23
|
+
grant_type_matches: "authorization_code",
|
24
|
+
grant_type_strategy: Doorkeeper::Request::AuthorizationCode,
|
25
|
+
)
|
26
|
+
|
27
|
+
register(
|
28
|
+
:client_credentials,
|
29
|
+
grant_type_matches: "client_credentials",
|
30
|
+
grant_type_strategy: Doorkeeper::Request::ClientCredentials,
|
31
|
+
)
|
32
|
+
|
33
|
+
register(
|
34
|
+
:password,
|
35
|
+
grant_type_matches: "password",
|
36
|
+
grant_type_strategy: Doorkeeper::Request::Password,
|
37
|
+
)
|
38
|
+
|
39
|
+
register(
|
40
|
+
:refresh_token,
|
41
|
+
grant_type_matches: "refresh_token",
|
42
|
+
grant_type_strategy: Doorkeeper::Request::RefreshToken,
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Doorkeeper
|
4
|
+
module GrantFlow
|
5
|
+
class Flow
|
6
|
+
attr_reader :name, :grant_type_matches, :grant_type_strategy,
|
7
|
+
:response_type_matches, :response_type_strategy,
|
8
|
+
:response_mode_matches
|
9
|
+
|
10
|
+
def initialize(name, **options)
|
11
|
+
@name = name
|
12
|
+
@grant_type_matches = options[:grant_type_matches]
|
13
|
+
@grant_type_strategy = options[:grant_type_strategy]
|
14
|
+
@response_type_matches = options[:response_type_matches]
|
15
|
+
@response_type_strategy = options[:response_type_strategy]
|
16
|
+
@response_mode_matches = options[:response_mode_matches]
|
17
|
+
end
|
18
|
+
|
19
|
+
def handles_grant_type?
|
20
|
+
grant_type_matches.present?
|
21
|
+
end
|
22
|
+
|
23
|
+
def handles_response_type?
|
24
|
+
response_type_matches.present?
|
25
|
+
end
|
26
|
+
|
27
|
+
def matches_grant_type?(value)
|
28
|
+
grant_type_matches === value
|
29
|
+
end
|
30
|
+
|
31
|
+
def matches_response_type?(value)
|
32
|
+
response_type_matches === value
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_response_mode
|
36
|
+
response_mode_matches[0]
|
37
|
+
end
|
38
|
+
|
39
|
+
def matches_response_mode?(value)
|
40
|
+
response_mode_matches.include?(value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|