doorkeeper 5.3.3 → 5.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +216 -9
- data/README.md +30 -21
- data/app/controllers/doorkeeper/application_controller.rb +1 -0
- data/app/controllers/doorkeeper/applications_controller.rb +4 -4
- data/app/controllers/doorkeeper/authorizations_controller.rb +66 -22
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +3 -3
- data/app/controllers/doorkeeper/token_info_controller.rb +12 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +73 -25
- data/app/helpers/doorkeeper/dashboard_helper.rb +1 -1
- data/app/views/doorkeeper/applications/_form.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +35 -14
- data/app/views/doorkeeper/authorizations/error.html.erb +3 -1
- data/app/views/doorkeeper/authorizations/form_post.html.erb +15 -0
- data/app/views/doorkeeper/authorizations/new.html.erb +16 -14
- data/config/locales/en.yml +9 -2
- data/lib/doorkeeper/config/abstract_builder.rb +28 -0
- data/lib/doorkeeper/config/option.rb +26 -14
- data/lib/doorkeeper/config/validations.rb +53 -0
- data/lib/doorkeeper/config.rb +182 -134
- data/lib/doorkeeper/engine.rb +10 -3
- 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/grant_flow.rb +45 -0
- data/lib/doorkeeper/grape/helpers.rb +1 -1
- data/lib/doorkeeper/helpers/controller.rb +9 -5
- data/lib/doorkeeper/models/access_grant_mixin.rb +22 -19
- data/lib/doorkeeper/models/access_token_mixin.rb +115 -52
- data/lib/doorkeeper/models/application_mixin.rb +5 -4
- data/lib/doorkeeper/models/concerns/expirable.rb +1 -1
- data/lib/doorkeeper/models/concerns/expiration_time_sql_math.rb +88 -0
- data/lib/doorkeeper/models/concerns/polymorphic_resource_owner.rb +30 -0
- data/lib/doorkeeper/models/concerns/resource_ownerable.rb +47 -0
- data/lib/doorkeeper/models/concerns/revocable.rb +1 -1
- data/lib/doorkeeper/models/concerns/scopes.rb +5 -1
- data/lib/doorkeeper/models/concerns/secret_storable.rb +1 -3
- data/lib/doorkeeper/oauth/authorization/code.rb +25 -6
- data/lib/doorkeeper/oauth/authorization/context.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/token.rb +24 -16
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +4 -4
- data/lib/doorkeeper/oauth/authorization_code_request.rb +34 -21
- data/lib/doorkeeper/oauth/base_request.rb +19 -26
- data/lib/doorkeeper/oauth/client/credentials.rb +2 -4
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +31 -15
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +4 -2
- data/lib/doorkeeper/oauth/client_credentials/validator.rb +5 -4
- data/lib/doorkeeper/oauth/client_credentials_request.rb +8 -7
- data/lib/doorkeeper/oauth/code_request.rb +4 -4
- data/lib/doorkeeper/oauth/code_response.rb +22 -12
- data/lib/doorkeeper/oauth/error_response.rb +7 -9
- data/lib/doorkeeper/oauth/forbidden_token_response.rb +2 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -8
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -2
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +4 -22
- data/lib/doorkeeper/oauth/hooks/context.rb +21 -0
- data/lib/doorkeeper/oauth/invalid_token_response.rb +2 -2
- data/lib/doorkeeper/oauth/password_access_token_request.rb +26 -8
- data/lib/doorkeeper/oauth/pre_authorization.rb +65 -33
- data/lib/doorkeeper/oauth/refresh_token_request.rb +42 -25
- data/lib/doorkeeper/oauth/token.rb +5 -6
- data/lib/doorkeeper/oauth/token_introspection.rb +8 -12
- data/lib/doorkeeper/oauth/token_request.rb +3 -3
- data/lib/doorkeeper/oauth/token_response.rb +2 -3
- data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +14 -4
- data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +34 -4
- data/lib/doorkeeper/orm/active_record/mixins/application.rb +28 -5
- data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +6 -1
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +5 -2
- data/lib/doorkeeper/orm/active_record.rb +30 -38
- data/lib/doorkeeper/rails/routes/abstract_router.rb +35 -0
- data/lib/doorkeeper/rails/routes/mapper.rb +2 -2
- data/lib/doorkeeper/rails/routes/registry.rb +45 -0
- data/lib/doorkeeper/rails/routes.rb +25 -22
- data/lib/doorkeeper/rake/db.rake +3 -3
- data/lib/doorkeeper/request/password.rb +1 -0
- data/lib/doorkeeper/request/refresh_token.rb +2 -1
- data/lib/doorkeeper/request/strategy.rb +2 -2
- data/lib/doorkeeper/request.rb +49 -12
- data/lib/doorkeeper/server.rb +4 -4
- data/lib/doorkeeper/stale_records_cleaner.rb +4 -4
- data/lib/doorkeeper/version.rb +2 -6
- data/lib/doorkeeper.rb +181 -81
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +1 -1
- data/lib/generators/doorkeeper/enable_polymorphic_resource_owner_generator.rb +39 -0
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb +3 -1
- data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb.erb +2 -0
- data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +2 -0
- data/lib/generators/doorkeeper/templates/enable_polymorphic_resource_owner_migration.rb.erb +17 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +73 -17
- data/lib/generators/doorkeeper/templates/migration.rb.erb +28 -9
- metadata +48 -316
- data/Appraisals +0 -40
- 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 -16
- data/doorkeeper.gemspec +0 -42
- data/gemfiles/rails_5_0.gemfile +0 -18
- data/gemfiles/rails_5_1.gemfile +0 -18
- data/gemfiles/rails_5_2.gemfile +0 -18
- data/gemfiles/rails_6_0.gemfile +0 -18
- data/gemfiles/rails_master.gemfile +0 -18
- 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 -608
- 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 -498
- 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 -7
- 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/application.rb +0 -49
- 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/config.ru +0 -6
- 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 -68
- 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/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 -809
- 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 -59
- data/spec/lib/models/scopes_spec.rb +0 -53
- 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 -170
- data/spec/lib/oauth/base_request_spec.rb +0 -224
- 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 -134
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -112
- data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -59
- data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -27
- data/spec/lib/oauth/client_credentials_request_spec.rb +0 -107
- 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 -32
- 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 -190
- data/spec/lib/oauth/pre_authorization_spec.rb +0 -223
- data/spec/lib/oauth/refresh_token_request_spec.rb +0 -177
- data/spec/lib/oauth/scopes_spec.rb +0 -146
- data/spec/lib/oauth/token_request_spec.rb +0 -157
- data/spec/lib/oauth/token_response_spec.rb +0 -84
- data/spec/lib/oauth/token_spec.rb +0 -156
- 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 -89
- data/spec/models/doorkeeper/access_grant_spec.rb +0 -161
- data/spec/models/doorkeeper/access_token_spec.rb +0 -622
- data/spec/models/doorkeeper/application_spec.rb +0 -482
- 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 -75
- data/spec/requests/flows/authorization_code_errors_spec.rb +0 -79
- data/spec/requests/flows/authorization_code_spec.rb +0 -525
- data/spec/requests/flows/client_credentials_spec.rb +0 -166
- 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 -233
- data/spec/requests/flows/revoke_token_spec.rb +0 -157
- 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 -13
- 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 -54
- data/spec/validators/redirect_uri_validator_spec.rb +0 -183
- data/spec/version/version_spec.rb +0 -17
@@ -5,16 +5,16 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
self.table_name =
|
8
|
+
self.table_name = compute_doorkeeper_table_name
|
9
|
+
self.strict_loading_by_default = false if respond_to?(:strict_loading_by_default)
|
9
10
|
|
10
11
|
include ::Doorkeeper::AccessGrantMixin
|
11
12
|
|
12
|
-
belongs_to :application, class_name: Doorkeeper.config.application_class,
|
13
|
+
belongs_to :application, class_name: Doorkeeper.config.application_class.to_s,
|
13
14
|
optional: true,
|
14
15
|
inverse_of: :access_grants
|
15
16
|
|
16
|
-
validates :
|
17
|
-
:application_id,
|
17
|
+
validates :application_id,
|
18
18
|
:token,
|
19
19
|
:expires_in,
|
20
20
|
:redirect_uri,
|
@@ -49,5 +49,15 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
49
49
|
secret_strategy.store_secret(self, :token, @raw_token)
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
53
|
+
module ClassMethods
|
54
|
+
private
|
55
|
+
|
56
|
+
def compute_doorkeeper_table_name
|
57
|
+
table_name = "oauth_access_grant"
|
58
|
+
table_name = table_name.pluralize if pluralize_table_names
|
59
|
+
"#{table_name_prefix}#{table_name}#{table_name_suffix}"
|
60
|
+
end
|
61
|
+
end
|
52
62
|
end
|
53
63
|
end
|
@@ -5,11 +5,12 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
self.table_name =
|
8
|
+
self.table_name = compute_doorkeeper_table_name
|
9
|
+
self.strict_loading_by_default = false if respond_to?(:strict_loading_by_default)
|
9
10
|
|
10
11
|
include ::Doorkeeper::AccessTokenMixin
|
11
12
|
|
12
|
-
belongs_to :application, class_name: Doorkeeper.config.application_class,
|
13
|
+
belongs_to :application, class_name: Doorkeeper.config.application_class.to_s,
|
13
14
|
inverse_of: :access_tokens,
|
14
15
|
optional: true
|
15
16
|
|
@@ -25,7 +26,7 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
25
26
|
on: :create, if: :use_refresh_token?
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
|
+
module ClassMethods
|
29
30
|
# Searches for not revoked Access Tokens associated with the
|
30
31
|
# specific Resource Owner.
|
31
32
|
#
|
@@ -36,12 +37,41 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
36
37
|
# active Access Tokens for Resource Owner
|
37
38
|
#
|
38
39
|
def active_for(resource_owner)
|
39
|
-
|
40
|
+
by_resource_owner(resource_owner).where(revoked_at: nil)
|
40
41
|
end
|
41
42
|
|
42
43
|
def refresh_token_revoked_on_use?
|
43
44
|
column_names.include?("previous_refresh_token")
|
44
45
|
end
|
46
|
+
|
47
|
+
# Returns non-expired and non-revoked access tokens
|
48
|
+
def not_expired
|
49
|
+
relation = where(revoked_at: nil)
|
50
|
+
|
51
|
+
if supports_expiration_time_math?
|
52
|
+
# have not reached the expiration time or it never expires
|
53
|
+
relation.where("#{expiration_time_sql} > ?", Time.now.utc).or(
|
54
|
+
relation.where(expires_in: nil)
|
55
|
+
)
|
56
|
+
else
|
57
|
+
::Kernel.warn <<~WARNING.squish
|
58
|
+
[DOORKEEPER] Doorkeeper doesn't support expiration time math for your database adapter (#{adapter_name}).
|
59
|
+
Please add a class method `custom_expiration_time_sql` for your AccessToken class/mixin to provide a custom
|
60
|
+
SQL expression to calculate access token expiration time. See lib/doorkeeper/orm/active_record/mixins/access_token.rb
|
61
|
+
for more details.
|
62
|
+
WARNING
|
63
|
+
|
64
|
+
relation
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def compute_doorkeeper_table_name
|
71
|
+
table_name = "oauth_access_token"
|
72
|
+
table_name = table_name.pluralize if pluralize_table_names
|
73
|
+
"#{table_name_prefix}#{table_name}#{table_name_suffix}"
|
74
|
+
end
|
45
75
|
end
|
46
76
|
end
|
47
77
|
end
|
@@ -5,7 +5,8 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
self.table_name =
|
8
|
+
self.table_name = compute_doorkeeper_table_name
|
9
|
+
self.strict_loading_by_default = false if respond_to?(:strict_loading_by_default)
|
9
10
|
|
10
11
|
include ::Doorkeeper::ApplicationMixin
|
11
12
|
|
@@ -43,7 +44,7 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
43
44
|
# @return [String] new transformed secret value
|
44
45
|
#
|
45
46
|
def renew_secret
|
46
|
-
@raw_secret =
|
47
|
+
@raw_secret = secret_generator.generate
|
47
48
|
secret_strategy.store_secret(self, :secret, @raw_secret)
|
48
49
|
end
|
49
50
|
|
@@ -101,6 +102,17 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
101
102
|
|
102
103
|
private
|
103
104
|
|
105
|
+
def secret_generator
|
106
|
+
generator_name = Doorkeeper.config.application_secret_generator
|
107
|
+
generator = generator_name.constantize
|
108
|
+
|
109
|
+
return generator if generator.respond_to?(:generate)
|
110
|
+
|
111
|
+
raise Errors::UnableToGenerateToken, "#{generator} does not respond to `.generate`."
|
112
|
+
rescue NameError
|
113
|
+
raise Errors::TokenGeneratorNotFound, "#{generator_name} not found"
|
114
|
+
end
|
115
|
+
|
104
116
|
def generate_uid
|
105
117
|
self.uid = Doorkeeper::OAuth::Helpers::UniqueToken.generate if uid.blank?
|
106
118
|
end
|
@@ -137,9 +149,9 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
137
149
|
only = Array.wrap(opts[:only]).map(&:to_s)
|
138
150
|
|
139
151
|
only = if only.blank?
|
140
|
-
|
152
|
+
client_serializable_attributes
|
141
153
|
else
|
142
|
-
only &
|
154
|
+
only & client_serializable_attributes
|
143
155
|
end
|
144
156
|
|
145
157
|
only -= Array.wrap(opts[:except]).map(&:to_s) if opts.key?(:except)
|
@@ -150,7 +162,10 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
150
162
|
# Override this method if you need additional attributes to be serialized.
|
151
163
|
#
|
152
164
|
# @return [Array<String>] collection of serializable attributes
|
153
|
-
|
165
|
+
#
|
166
|
+
# NOTE: `serializable_attributes` method already taken by Rails >= 6
|
167
|
+
#
|
168
|
+
def client_serializable_attributes
|
154
169
|
attributes = %w[id name created_at]
|
155
170
|
attributes << "uid" unless confidential?
|
156
171
|
attributes
|
@@ -182,6 +197,14 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
|
|
182
197
|
Doorkeeper.config.access_token_model.revoke_all_for(id, resource_owner)
|
183
198
|
Doorkeeper.config.access_grant_model.revoke_all_for(id, resource_owner)
|
184
199
|
end
|
200
|
+
|
201
|
+
private
|
202
|
+
|
203
|
+
def compute_doorkeeper_table_name
|
204
|
+
table_name = "oauth_application"
|
205
|
+
table_name = table_name.pluralize if pluralize_table_names
|
206
|
+
"#{table_name_prefix}#{table_name}#{table_name_suffix}"
|
207
|
+
end
|
185
208
|
end
|
186
209
|
end
|
187
210
|
end
|
@@ -21,6 +21,7 @@ module Doorkeeper
|
|
21
21
|
record.errors.add(attribute, :unspecified_scheme) if unspecified_scheme?(uri)
|
22
22
|
record.errors.add(attribute, :relative_uri) if relative_uri?(uri)
|
23
23
|
record.errors.add(attribute, :secured_uri) if invalid_ssl_uri?(uri)
|
24
|
+
record.errors.add(attribute, :invalid_uri) if unspecified_host?(uri)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
rescue URI::InvalidURIError
|
@@ -43,8 +44,12 @@ module Doorkeeper
|
|
43
44
|
%w[localhost].include?(uri.try(:scheme))
|
44
45
|
end
|
45
46
|
|
47
|
+
def unspecified_host?(uri)
|
48
|
+
uri.is_a?(URI::HTTP) && uri.host.blank?
|
49
|
+
end
|
50
|
+
|
46
51
|
def relative_uri?(uri)
|
47
|
-
uri.scheme.nil? && uri.host.
|
52
|
+
uri.scheme.nil? && uri.host.blank?
|
48
53
|
end
|
49
54
|
|
50
55
|
def invalid_ssl_uri?(uri)
|
@@ -15,7 +15,8 @@ module Doorkeeper
|
|
15
15
|
def clean_revoked
|
16
16
|
table = @base_scope.arel_table
|
17
17
|
|
18
|
-
@base_scope
|
18
|
+
@base_scope
|
19
|
+
.where.not(revoked_at: nil)
|
19
20
|
.where(table[:revoked_at].lt(Time.current))
|
20
21
|
.in_batches(&:delete_all)
|
21
22
|
end
|
@@ -24,7 +25,9 @@ module Doorkeeper
|
|
24
25
|
def clean_expired(ttl)
|
25
26
|
table = @base_scope.arel_table
|
26
27
|
|
27
|
-
@base_scope
|
28
|
+
@base_scope
|
29
|
+
.where.not(expires_in: nil)
|
30
|
+
.where(table[:created_at].lt(Time.current - ttl))
|
28
31
|
.in_batches(&:delete_all)
|
29
32
|
end
|
30
33
|
end
|
@@ -1,52 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_support/lazy_load_hooks"
|
4
|
-
|
5
3
|
module Doorkeeper
|
4
|
+
autoload :AccessGrant, "doorkeeper/orm/active_record/access_grant"
|
5
|
+
autoload :AccessToken, "doorkeeper/orm/active_record/access_token"
|
6
|
+
autoload :Application, "doorkeeper/orm/active_record/application"
|
7
|
+
autoload :RedirectUriValidator, "doorkeeper/orm/active_record/redirect_uri_validator"
|
8
|
+
|
9
|
+
module Models
|
10
|
+
autoload :Ownership, "doorkeeper/models/concerns/ownership"
|
11
|
+
end
|
12
|
+
|
13
|
+
# ActiveRecord ORM for Doorkeeper entity models.
|
14
|
+
# Consists of three main OAuth entities:
|
15
|
+
# * Access Token
|
16
|
+
# * Access Grant
|
17
|
+
# * Application (client)
|
18
|
+
#
|
19
|
+
# Do a lazy loading of all the required and configured stuff.
|
20
|
+
#
|
6
21
|
module Orm
|
7
|
-
# ActiveRecord ORM for Doorkeeper entity models.
|
8
|
-
# Consists of three main OAuth entities:
|
9
|
-
# * Access Token
|
10
|
-
# * Access Grant
|
11
|
-
# * Application (client)
|
12
|
-
#
|
13
|
-
# Do a lazy loading of all the required and configured stuff.
|
14
|
-
#
|
15
22
|
module ActiveRecord
|
16
|
-
|
17
|
-
lazy_load do
|
18
|
-
require "doorkeeper/orm/active_record/stale_records_cleaner"
|
19
|
-
require "doorkeeper/orm/active_record/access_grant"
|
20
|
-
require "doorkeeper/orm/active_record/access_token"
|
21
|
-
require "doorkeeper/orm/active_record/application"
|
23
|
+
autoload :StaleRecordsCleaner, "doorkeeper/orm/active_record/stale_records_cleaner"
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
25
|
+
module Mixins
|
26
|
+
autoload :AccessGrant, "doorkeeper/orm/active_record/mixins/access_grant"
|
27
|
+
autoload :AccessToken, "doorkeeper/orm/active_record/mixins/access_token"
|
28
|
+
autoload :Application, "doorkeeper/orm/active_record/mixins/application"
|
30
29
|
end
|
31
30
|
|
32
|
-
def self.
|
33
|
-
|
34
|
-
require "doorkeeper/models/concerns/ownership"
|
35
|
-
|
36
|
-
Doorkeeper.config.application_model.send :include, Doorkeeper::Models::Ownership
|
37
|
-
end
|
31
|
+
def self.run_hooks
|
32
|
+
initialize_configured_associations
|
38
33
|
end
|
39
34
|
|
40
|
-
def self.
|
41
|
-
|
42
|
-
|
35
|
+
def self.initialize_configured_associations
|
36
|
+
if Doorkeeper.config.enable_application_owner?
|
37
|
+
Doorkeeper.config.application_model.include ::Doorkeeper::Models::Ownership
|
38
|
+
end
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
Doorkeeper::AccessGrant,
|
47
|
-
Doorkeeper::AccessToken,
|
48
|
-
Doorkeeper::Application,
|
49
|
-
]
|
40
|
+
Doorkeeper.config.access_grant_model.include ::Doorkeeper::Models::PolymorphicResourceOwner::ForAccessGrant
|
41
|
+
Doorkeeper.config.access_token_model.include ::Doorkeeper::Models::PolymorphicResourceOwner::ForAccessToken
|
50
42
|
end
|
51
43
|
end
|
52
44
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Doorkeeper
|
4
|
+
module Rails
|
5
|
+
# Abstract router module that implements base behavior
|
6
|
+
# for generating and mapping Rails routes.
|
7
|
+
#
|
8
|
+
# Could be reused in Doorkeeper extensions.
|
9
|
+
#
|
10
|
+
module AbstractRouter
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
attr_reader :routes
|
14
|
+
|
15
|
+
def initialize(routes, mapper = Mapper.new, &block)
|
16
|
+
@routes = routes
|
17
|
+
@mapping = mapper.map(&block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_routes!(**_options)
|
21
|
+
raise NotImplementedError, "must be redefined for #{self.class.name}!"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def map_route(name, method)
|
27
|
+
return if @mapping.skipped?(name)
|
28
|
+
|
29
|
+
send(method, @mapping[name])
|
30
|
+
|
31
|
+
mapping[name] = @mapping[name]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Doorkeeper
|
4
|
+
module Rails
|
5
|
+
class Routes
|
6
|
+
# Thread-safe registry of any Doorkeeper additional routes.
|
7
|
+
# Used to allow implementing of Doorkeeper extensions that must
|
8
|
+
# use their own routes.
|
9
|
+
#
|
10
|
+
module Registry
|
11
|
+
ROUTES_ACCESS_LOCK = Mutex.new
|
12
|
+
ROUTES_DEFINITION_LOCK = Mutex.new
|
13
|
+
|
14
|
+
InvalidRouterClass = Class.new(StandardError)
|
15
|
+
|
16
|
+
# Collection of additional registered routes for Doorkeeper.
|
17
|
+
#
|
18
|
+
# @return [Array<Object>] set of registered routes
|
19
|
+
#
|
20
|
+
def registered_routes
|
21
|
+
ROUTES_DEFINITION_LOCK.synchronize do
|
22
|
+
@registered_routes ||= Set.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Registers additional routes in the Doorkeeper registry
|
27
|
+
#
|
28
|
+
# @param [Object] routes
|
29
|
+
# routes class
|
30
|
+
#
|
31
|
+
def register_routes(routes)
|
32
|
+
if !routes.is_a?(Module) || !(routes < AbstractRouter)
|
33
|
+
raise InvalidRouterClass, "routes class must include Doorkeeper::Rails::AbstractRouter"
|
34
|
+
end
|
35
|
+
|
36
|
+
ROUTES_ACCESS_LOCK.synchronize do
|
37
|
+
registered_routes << routes
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
alias register register_routes
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -2,31 +2,33 @@
|
|
2
2
|
|
3
3
|
require "doorkeeper/rails/routes/mapping"
|
4
4
|
require "doorkeeper/rails/routes/mapper"
|
5
|
+
require "doorkeeper/rails/routes/abstract_router"
|
6
|
+
require "doorkeeper/rails/routes/registry"
|
5
7
|
|
6
8
|
module Doorkeeper
|
7
9
|
module Rails
|
8
10
|
class Routes # :nodoc:
|
9
|
-
mattr_reader :mapping do
|
10
|
-
{}
|
11
|
-
end
|
12
|
-
|
13
11
|
module Helper
|
14
12
|
def use_doorkeeper(options = {}, &block)
|
15
13
|
Doorkeeper::Rails::Routes.new(self, &block).generate_routes!(options)
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
|
-
|
20
|
-
|
17
|
+
include AbstractRouter
|
18
|
+
extend Registry
|
19
|
+
|
20
|
+
mattr_reader :mapping do
|
21
|
+
{}
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
+
def self.install!
|
25
|
+
ActionDispatch::Routing::Mapper.include Doorkeeper::Rails::Routes::Helper
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
@mapping = Mapper.new.map(&block)
|
27
|
+
registered_routes.each(&:install!)
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
+
def initialize(routes, mapper = Mapper.new, &block)
|
31
|
+
super
|
30
32
|
end
|
31
33
|
|
32
34
|
def generate_routes!(options)
|
@@ -34,7 +36,7 @@ module Doorkeeper
|
|
34
36
|
map_route(:authorizations, :authorization_routes)
|
35
37
|
map_route(:tokens, :token_routes)
|
36
38
|
map_route(:tokens, :revoke_routes)
|
37
|
-
map_route(:tokens, :introspect_routes)
|
39
|
+
map_route(:tokens, :introspect_routes) if introspection_routes?
|
38
40
|
map_route(:applications, :application_routes)
|
39
41
|
map_route(:authorized_applications, :authorized_applications_routes)
|
40
42
|
map_route(:token_info, :token_info_routes)
|
@@ -43,14 +45,6 @@ module Doorkeeper
|
|
43
45
|
|
44
46
|
private
|
45
47
|
|
46
|
-
def map_route(name, method)
|
47
|
-
return if @mapping.skipped?(name)
|
48
|
-
|
49
|
-
send(method, @mapping[name])
|
50
|
-
|
51
|
-
mapping[name] = @mapping[name]
|
52
|
-
end
|
53
|
-
|
54
48
|
def authorization_routes(mapping)
|
55
49
|
routes.resource(
|
56
50
|
:authorization,
|
@@ -59,8 +53,8 @@ module Doorkeeper
|
|
59
53
|
as: mapping[:as],
|
60
54
|
controller: mapping[:controllers],
|
61
55
|
) do
|
62
|
-
routes.get
|
63
|
-
routes.get
|
56
|
+
routes.get native_authorization_code_route, action: :show, on: :member
|
57
|
+
routes.get '/', action: :new, on: :member
|
64
58
|
end
|
65
59
|
end
|
66
60
|
|
@@ -102,6 +96,15 @@ module Doorkeeper
|
|
102
96
|
only: %i[index destroy],
|
103
97
|
controller: mapping[:controllers]
|
104
98
|
end
|
99
|
+
|
100
|
+
def native_authorization_code_route
|
101
|
+
Doorkeeper.configuration.native_authorization_code_route
|
102
|
+
end
|
103
|
+
|
104
|
+
def introspection_routes?
|
105
|
+
Doorkeeper.configured? &&
|
106
|
+
!Doorkeeper.config.allow_token_introspection.is_a?(FalseClass)
|
107
|
+
end
|
105
108
|
end
|
106
109
|
end
|
107
110
|
end
|
data/lib/doorkeeper/rake/db.rake
CHANGED
@@ -13,7 +13,7 @@ namespace :doorkeeper do
|
|
13
13
|
namespace :cleanup do
|
14
14
|
desc "Removes stale access tokens"
|
15
15
|
task revoked_tokens: "doorkeeper:setup" do
|
16
|
-
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper
|
16
|
+
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper.config.access_token_model)
|
17
17
|
cleaner.clean_revoked
|
18
18
|
end
|
19
19
|
|
@@ -26,13 +26,13 @@ namespace :doorkeeper do
|
|
26
26
|
|
27
27
|
desc "Removes stale access grants"
|
28
28
|
task revoked_grants: "doorkeeper:setup" do
|
29
|
-
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper
|
29
|
+
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper.config.access_grant_model)
|
30
30
|
cleaner.clean_revoked
|
31
31
|
end
|
32
32
|
|
33
33
|
desc "Removes expired (TTL passed) access grants"
|
34
34
|
task expired_grants: "doorkeeper:setup" do
|
35
|
-
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper
|
35
|
+
cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper.config.access_grant_model)
|
36
36
|
cleaner.clean_expired(Doorkeeper.config.authorization_code_expires_in)
|
37
37
|
end
|
38
38
|
end
|
data/lib/doorkeeper/request.rb
CHANGED
@@ -4,32 +4,69 @@ module Doorkeeper
|
|
4
4
|
module Request
|
5
5
|
class << self
|
6
6
|
def authorization_strategy(response_type)
|
7
|
-
|
7
|
+
grant_flow = authorization_flows.detect do |flow|
|
8
|
+
flow.matches_response_type?(response_type)
|
9
|
+
end
|
10
|
+
|
11
|
+
if grant_flow
|
12
|
+
grant_flow.response_type_strategy
|
13
|
+
else
|
14
|
+
# [NOTE]: this will be removed in a newer versions of Doorkeeper.
|
15
|
+
# For retro-compatibility only
|
16
|
+
build_fallback_strategy_class(response_type)
|
17
|
+
end
|
8
18
|
end
|
9
19
|
|
10
20
|
def token_strategy(grant_type)
|
11
21
|
raise Errors::MissingRequiredParameter, :grant_type if grant_type.blank?
|
12
22
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
23
|
+
grant_flow = token_flows.detect do |flow|
|
24
|
+
flow.matches_grant_type?(grant_type)
|
25
|
+
end
|
17
26
|
|
18
|
-
|
19
|
-
|
27
|
+
if grant_flow
|
28
|
+
grant_flow.grant_type_strategy
|
29
|
+
else
|
30
|
+
# [NOTE]: this will be removed in a newer versions of Doorkeeper.
|
31
|
+
# For retro-compatibility only
|
32
|
+
raise Errors::InvalidTokenStrategy unless available.include?(grant_type.to_s)
|
20
33
|
|
21
|
-
|
34
|
+
strategy_class = build_fallback_strategy_class(grant_type)
|
35
|
+
raise Errors::InvalidTokenStrategy unless strategy_class
|
36
|
+
|
37
|
+
strategy_class
|
38
|
+
end
|
22
39
|
end
|
23
40
|
|
24
41
|
private
|
25
42
|
|
26
|
-
def
|
27
|
-
Doorkeeper.
|
43
|
+
def authorization_flows
|
44
|
+
Doorkeeper.configuration.authorization_response_flows
|
45
|
+
end
|
46
|
+
|
47
|
+
def token_flows
|
48
|
+
Doorkeeper.configuration.token_grant_flows
|
28
49
|
end
|
29
50
|
|
30
|
-
|
51
|
+
# [NOTE]: this will be removed in a newer versions of Doorkeeper.
|
52
|
+
# For retro-compatibility only
|
53
|
+
def available
|
54
|
+
Doorkeeper.config.deprecated_token_grant_types_resolver
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_fallback_strategy_class(grant_or_request_type)
|
31
58
|
strategy_class_name = grant_or_request_type.to_s.tr(" ", "_").camelize
|
32
|
-
"Doorkeeper::Request::#{strategy_class_name}".constantize
|
59
|
+
fallback_strategy = "Doorkeeper::Request::#{strategy_class_name}".constantize
|
60
|
+
|
61
|
+
::Kernel.warn <<~WARNING
|
62
|
+
[DOORKEEPER] #{fallback_strategy} found using fallback, it must be
|
63
|
+
registered using `Doorkeeper::GrantFlow.register(grant_flow_name, **options)`.
|
64
|
+
This functionality will be removed in a newer versions of Doorkeeper.
|
65
|
+
WARNING
|
66
|
+
|
67
|
+
fallback_strategy
|
68
|
+
rescue NameError
|
69
|
+
raise Errors::InvalidTokenStrategy
|
33
70
|
end
|
34
71
|
end
|
35
72
|
end
|
data/lib/doorkeeper/server.rb
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
module Doorkeeper
|
4
4
|
class Server
|
5
|
-
|
5
|
+
attr_reader :context
|
6
6
|
|
7
|
-
def initialize(context
|
7
|
+
def initialize(context)
|
8
8
|
@context = context
|
9
9
|
end
|
10
10
|
|
11
11
|
def authorization_request(strategy)
|
12
|
-
klass = Request.authorization_strategy
|
12
|
+
klass = Request.authorization_strategy(strategy)
|
13
13
|
klass.new(self)
|
14
14
|
end
|
15
15
|
|
16
16
|
def token_request(strategy)
|
17
|
-
klass = Request.token_strategy
|
17
|
+
klass = Request.token_strategy(strategy)
|
18
18
|
klass.new(self)
|
19
19
|
end
|
20
20
|
|
@@ -13,12 +13,12 @@ module Doorkeeper
|
|
13
13
|
raise Doorkeeper::Errors::NoOrmCleaner, "'#{configured_orm}' ORM has no cleaner!"
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.configured_orm
|
17
|
-
Doorkeeper.config.orm
|
18
|
-
end
|
19
|
-
|
20
16
|
def self.new(base_scope)
|
21
17
|
self.for(base_scope)
|
22
18
|
end
|
19
|
+
|
20
|
+
def self.configured_orm
|
21
|
+
Doorkeeper.config.orm
|
22
|
+
end
|
23
23
|
end
|
24
24
|
end
|