doorkeeper 4.2.6 → 5.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +25 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +17 -0
- data/.gitignore +2 -1
- data/.hound.yml +2 -13
- data/.rubocop.yml +17 -0
- data/.travis.yml +19 -5
- data/Appraisals +8 -4
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +1 -1
- data/NEWS.md +77 -0
- data/README.md +169 -34
- data/Rakefile +6 -0
- data/SECURITY.md +15 -0
- data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
- data/app/controllers/doorkeeper/application_controller.rb +2 -5
- data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
- data/app/controllers/doorkeeper/applications_controller.rb +47 -13
- data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +15 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +15 -7
- data/app/helpers/doorkeeper/dashboard_helper.rb +8 -6
- data/app/validators/redirect_uri_validator.rb +13 -2
- data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
- data/app/views/doorkeeper/applications/_form.html.erb +31 -19
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/index.html.erb +18 -6
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +8 -5
- data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
- data/app/views/doorkeeper/authorized_applications/index.html.erb +0 -1
- data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
- data/config/locales/en.yml +18 -6
- data/doorkeeper.gemspec +6 -5
- data/gemfiles/rails_4_2.gemfile +6 -4
- data/gemfiles/rails_5_0.gemfile +4 -4
- data/gemfiles/rails_5_1.gemfile +6 -7
- data/gemfiles/rails_5_2.gemfile +12 -0
- data/gemfiles/rails_master.gemfile +14 -0
- data/lib/doorkeeper/config.rb +107 -68
- data/lib/doorkeeper/engine.rb +7 -3
- data/lib/doorkeeper/errors.rb +2 -5
- data/lib/doorkeeper/grape/helpers.rb +14 -9
- data/lib/doorkeeper/helpers/controller.rb +15 -6
- data/lib/doorkeeper/models/access_grant_mixin.rb +52 -23
- data/lib/doorkeeper/models/access_token_mixin.rb +51 -52
- data/lib/doorkeeper/models/application_mixin.rb +16 -30
- data/lib/doorkeeper/models/concerns/expirable.rb +7 -5
- data/lib/doorkeeper/models/concerns/orderable.rb +13 -0
- data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
- data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +41 -20
- data/lib/doorkeeper/oauth/authorization_code_request.rb +33 -3
- data/lib/doorkeeper/oauth/base_request.rb +22 -7
- data/lib/doorkeeper/oauth/client/credentials.rb +6 -4
- data/lib/doorkeeper/oauth/client.rb +2 -2
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -1
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -2
- data/lib/doorkeeper/oauth/error.rb +2 -2
- data/lib/doorkeeper/oauth/error_response.rb +11 -4
- data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +15 -0
- data/lib/doorkeeper/oauth/invalid_token_response.rb +3 -4
- data/lib/doorkeeper/oauth/password_access_token_request.rb +8 -4
- data/lib/doorkeeper/oauth/pre_authorization.rb +45 -13
- data/lib/doorkeeper/oauth/refresh_token_request.rb +7 -1
- data/lib/doorkeeper/oauth/scopes.rb +19 -9
- data/lib/doorkeeper/oauth/token.rb +6 -3
- data/lib/doorkeeper/oauth/token_introspection.rb +128 -0
- data/lib/doorkeeper/oauth/token_response.rb +4 -2
- data/lib/doorkeeper/oauth.rb +13 -0
- data/lib/doorkeeper/orm/active_record/access_grant.rb +27 -0
- data/lib/doorkeeper/orm/active_record/access_token.rb +21 -20
- data/lib/doorkeeper/orm/active_record/application.rb +34 -0
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
- data/lib/doorkeeper/orm/active_record.rb +21 -8
- data/lib/doorkeeper/rails/helpers.rb +7 -10
- data/lib/doorkeeper/rails/routes.rb +21 -7
- data/lib/doorkeeper/rake/db.rake +40 -0
- data/lib/doorkeeper/rake/setup.rake +6 -0
- data/lib/doorkeeper/rake.rb +14 -0
- data/lib/doorkeeper/request/password.rb +1 -11
- data/lib/doorkeeper/request.rb +29 -23
- data/lib/doorkeeper/validations.rb +3 -2
- data/lib/doorkeeper/version.rb +14 -1
- data/lib/doorkeeper.rb +6 -17
- data/lib/generators/doorkeeper/application_owner_generator.rb +26 -12
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
- data/lib/generators/doorkeeper/install_generator.rb +17 -9
- data/lib/generators/doorkeeper/migration_generator.rb +26 -9
- data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +31 -20
- data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
- data/lib/generators/doorkeeper/templates/{add_owner_to_application_migration.rb → add_owner_to_application_migration.rb.erb} +1 -1
- data/lib/generators/doorkeeper/templates/{add_previous_refresh_token_to_access_tokens.rb → add_previous_refresh_token_to_access_tokens.rb.erb} +1 -1
- data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +88 -10
- data/lib/generators/doorkeeper/templates/{migration.rb → migration.rb.erb} +2 -1
- data/lib/generators/doorkeeper/views_generator.rb +3 -1
- data/spec/controllers/application_metal_controller_spec.rb +50 -0
- data/spec/controllers/applications_controller_spec.rb +141 -17
- data/spec/controllers/authorizations_controller_spec.rb +255 -20
- data/spec/controllers/protected_resources_controller_spec.rb +44 -35
- data/spec/controllers/token_info_controller_spec.rb +17 -21
- data/spec/controllers/tokens_controller_spec.rb +142 -10
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/config/environments/test.rb +4 -5
- data/spec/dummy/config/initializers/doorkeeper.rb +18 -1
- data/spec/dummy/config/initializers/{active_record_belongs_to_required_by_default.rb → new_framework_defaults.rb} +5 -1
- data/spec/dummy/config/initializers/secret_token.rb +0 -1
- data/spec/dummy/config/routes.rb +3 -42
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +3 -1
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +3 -1
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -1
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +3 -1
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +3 -1
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +13 -0
- data/spec/dummy/db/schema.rb +38 -37
- data/spec/factories.rb +1 -1
- data/spec/generators/application_owner_generator_spec.rb +25 -6
- data/spec/generators/confidential_applications_generator_spec.rb +45 -0
- data/spec/generators/install_generator_spec.rb +1 -1
- data/spec/generators/migration_generator_spec.rb +25 -4
- data/spec/generators/pkce_generator_spec.rb +43 -0
- data/spec/generators/previous_refresh_token_generator_spec.rb +57 -0
- data/spec/generators/views_generator_spec.rb +1 -1
- data/spec/grape/grape_integration_spec.rb +135 -0
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +2 -2
- data/spec/lib/config_spec.rb +170 -22
- data/spec/lib/doorkeeper_spec.rb +1 -126
- data/spec/lib/models/expirable_spec.rb +0 -3
- data/spec/lib/models/revocable_spec.rb +2 -4
- data/spec/lib/models/scopes_spec.rb +0 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +63 -13
- data/spec/lib/oauth/base_request_spec.rb +19 -10
- data/spec/lib/oauth/base_response_spec.rb +1 -1
- data/spec/lib/oauth/client/credentials_spec.rb +5 -5
- data/spec/lib/oauth/client_credentials/creator_spec.rb +6 -2
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
- data/spec/lib/oauth/client_credentials_integration_spec.rb +2 -2
- data/spec/lib/oauth/client_credentials_request_spec.rb +4 -5
- data/spec/lib/oauth/client_spec.rb +0 -3
- data/spec/lib/oauth/code_request_spec.rb +5 -5
- data/spec/lib/oauth/error_response_spec.rb +0 -3
- data/spec/lib/oauth/error_spec.rb +1 -3
- data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +115 -3
- data/spec/lib/oauth/invalid_token_response_spec.rb +2 -5
- data/spec/lib/oauth/password_access_token_request_spec.rb +46 -5
- data/spec/lib/oauth/pre_authorization_spec.rb +40 -6
- data/spec/lib/oauth/refresh_token_request_spec.rb +30 -14
- data/spec/lib/oauth/scopes_spec.rb +28 -4
- data/spec/lib/oauth/token_request_spec.rb +10 -13
- data/spec/lib/oauth/token_response_spec.rb +0 -1
- data/spec/lib/oauth/token_spec.rb +37 -14
- data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
- data/spec/lib/request/strategy_spec.rb +0 -1
- data/spec/lib/server_spec.rb +10 -0
- data/spec/models/doorkeeper/access_grant_spec.rb +2 -2
- data/spec/models/doorkeeper/access_token_spec.rb +118 -60
- data/spec/models/doorkeeper/application_spec.rb +101 -23
- data/spec/requests/applications/applications_request_spec.rb +94 -6
- data/spec/requests/applications/authorized_applications_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +15 -6
- data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
- data/spec/requests/flows/authorization_code_spec.rb +198 -1
- data/spec/requests/flows/client_credentials_spec.rb +73 -5
- data/spec/requests/flows/implicit_grant_errors_spec.rb +3 -3
- data/spec/requests/flows/implicit_grant_spec.rb +38 -11
- data/spec/requests/flows/password_spec.rb +160 -24
- data/spec/requests/flows/refresh_token_spec.rb +6 -6
- data/spec/requests/flows/revoke_token_spec.rb +26 -26
- data/spec/requests/flows/skip_authorization_spec.rb +16 -11
- data/spec/requests/protected_resources/metal_spec.rb +2 -2
- data/spec/requests/protected_resources/private_api_spec.rb +2 -2
- data/spec/routing/custom_controller_routes_spec.rb +63 -7
- data/spec/routing/default_routes_spec.rb +6 -2
- data/spec/routing/scoped_routes_spec.rb +16 -2
- data/spec/spec_helper.rb +54 -3
- data/spec/spec_helper_integration.rb +2 -63
- data/spec/support/dependencies/factory_bot.rb +2 -0
- data/spec/support/doorkeeper_rspec.rb +19 -0
- data/spec/support/helpers/access_token_request_helper.rb +1 -1
- data/spec/support/helpers/authorization_request_helper.rb +4 -4
- data/spec/support/helpers/model_helper.rb +9 -4
- data/spec/support/helpers/request_spec_helper.rb +10 -6
- data/spec/support/helpers/url_helper.rb +15 -10
- data/spec/support/http_method_shim.rb +12 -16
- data/spec/support/shared/controllers_shared_context.rb +2 -6
- data/spec/support/shared/models_shared_examples.rb +4 -4
- data/spec/validators/redirect_uri_validator_spec.rb +58 -7
- data/spec/version/version_spec.rb +15 -0
- data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
- metadata +73 -19
- data/spec/controllers/application_metal_controller.rb +0 -10
- data/spec/support/dependencies/factory_girl.rb +0 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Doorkeeper
|
|
4
|
+
module Orm
|
|
5
|
+
module ActiveRecord
|
|
6
|
+
class StaleRecordsCleaner
|
|
7
|
+
def initialize(base_scope)
|
|
8
|
+
@base_scope = base_scope
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def clean_revoked
|
|
12
|
+
table = @base_scope.arel_table
|
|
13
|
+
@base_scope.where.not(revoked_at: nil)
|
|
14
|
+
.where(table[:revoked_at].lt(Time.current))
|
|
15
|
+
.delete_all
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def clean_expired(ttl)
|
|
19
|
+
table = @base_scope.arel_table
|
|
20
|
+
@base_scope.where(table[:created_at].lt(Time.current - ttl))
|
|
21
|
+
.delete_all
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -1,22 +1,35 @@
|
|
|
1
|
+
require 'active_support/lazy_load_hooks'
|
|
2
|
+
|
|
3
|
+
require 'doorkeeper/orm/active_record/stale_records_cleaner'
|
|
4
|
+
|
|
1
5
|
module Doorkeeper
|
|
2
6
|
module Orm
|
|
3
7
|
module ActiveRecord
|
|
4
8
|
def self.initialize_models!
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
lazy_load do
|
|
10
|
+
require 'doorkeeper/orm/active_record/access_grant'
|
|
11
|
+
require 'doorkeeper/orm/active_record/access_token'
|
|
12
|
+
require 'doorkeeper/orm/active_record/application'
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
if Doorkeeper.configuration.active_record_options[:establish_connection]
|
|
15
|
+
[Doorkeeper::AccessGrant, Doorkeeper::AccessToken, Doorkeeper::Application].each do |model|
|
|
16
|
+
options = Doorkeeper.configuration.active_record_options[:establish_connection]
|
|
17
|
+
model.establish_connection(options)
|
|
18
|
+
end
|
|
12
19
|
end
|
|
13
20
|
end
|
|
14
21
|
end
|
|
15
22
|
|
|
16
23
|
def self.initialize_application_owner!
|
|
17
|
-
|
|
24
|
+
lazy_load do
|
|
25
|
+
require 'doorkeeper/models/concerns/ownership'
|
|
26
|
+
|
|
27
|
+
Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
|
|
28
|
+
end
|
|
29
|
+
end
|
|
18
30
|
|
|
19
|
-
|
|
31
|
+
def self.lazy_load(&block)
|
|
32
|
+
ActiveSupport.on_load(:active_record, {}, &block)
|
|
20
33
|
end
|
|
21
34
|
end
|
|
22
35
|
end
|
|
@@ -4,16 +4,12 @@ module Doorkeeper
|
|
|
4
4
|
def doorkeeper_authorize!(*scopes)
|
|
5
5
|
@_doorkeeper_scopes = scopes.presence || Doorkeeper.configuration.default_scopes
|
|
6
6
|
|
|
7
|
-
unless valid_doorkeeper_token?
|
|
8
|
-
doorkeeper_render_error
|
|
9
|
-
end
|
|
7
|
+
doorkeeper_render_error unless valid_doorkeeper_token?
|
|
10
8
|
end
|
|
11
9
|
|
|
12
|
-
def doorkeeper_unauthorized_render_options(
|
|
13
|
-
end
|
|
10
|
+
def doorkeeper_unauthorized_render_options(**); end
|
|
14
11
|
|
|
15
|
-
def doorkeeper_forbidden_render_options(
|
|
16
|
-
end
|
|
12
|
+
def doorkeeper_forbidden_render_options(**); end
|
|
17
13
|
|
|
18
14
|
def valid_doorkeeper_token?
|
|
19
15
|
doorkeeper_token && doorkeeper_token.acceptable?(@_doorkeeper_scopes)
|
|
@@ -23,14 +19,15 @@ module Doorkeeper
|
|
|
23
19
|
|
|
24
20
|
def doorkeeper_render_error
|
|
25
21
|
error = doorkeeper_error
|
|
26
|
-
headers.merge!
|
|
22
|
+
headers.merge!(error.headers.reject { |k| k == "Content-Type" })
|
|
27
23
|
doorkeeper_render_error_with(error)
|
|
28
24
|
end
|
|
29
25
|
|
|
30
26
|
def doorkeeper_render_error_with(error)
|
|
31
27
|
options = doorkeeper_render_options(error) || {}
|
|
32
28
|
status = doorkeeper_status_for_error(
|
|
33
|
-
error, options.delete(:respond_not_found_when_forbidden)
|
|
29
|
+
error, options.delete(:respond_not_found_when_forbidden)
|
|
30
|
+
)
|
|
34
31
|
if options.blank?
|
|
35
32
|
head status
|
|
36
33
|
else
|
|
@@ -69,7 +66,7 @@ module Doorkeeper
|
|
|
69
66
|
end
|
|
70
67
|
|
|
71
68
|
def doorkeeper_token
|
|
72
|
-
@
|
|
69
|
+
@doorkeeper_token ||= OAuth::Token.authenticate(
|
|
73
70
|
request,
|
|
74
71
|
*Doorkeeper.configuration.access_token_methods
|
|
75
72
|
)
|
|
@@ -4,8 +4,11 @@ require 'doorkeeper/rails/routes/mapper'
|
|
|
4
4
|
module Doorkeeper
|
|
5
5
|
module Rails
|
|
6
6
|
class Routes # :nodoc:
|
|
7
|
+
mattr_reader :mapping do
|
|
8
|
+
{}
|
|
9
|
+
end
|
|
10
|
+
|
|
7
11
|
module Helper
|
|
8
|
-
# TODO: options hash is not being used
|
|
9
12
|
def use_doorkeeper(options = {}, &block)
|
|
10
13
|
Doorkeeper::Rails::Routes.new(self, &block).generate_routes!(options)
|
|
11
14
|
end
|
|
@@ -20,6 +23,10 @@ module Doorkeeper
|
|
|
20
23
|
def initialize(routes, &block)
|
|
21
24
|
@routes = routes
|
|
22
25
|
@mapping = Mapper.new.map(&block)
|
|
26
|
+
|
|
27
|
+
if Doorkeeper.configuration.api_only
|
|
28
|
+
@mapping.skips.push(:applications, :authorized_applications)
|
|
29
|
+
end
|
|
23
30
|
end
|
|
24
31
|
|
|
25
32
|
def generate_routes!(options)
|
|
@@ -27,6 +34,7 @@ module Doorkeeper
|
|
|
27
34
|
map_route(:authorizations, :authorization_routes)
|
|
28
35
|
map_route(:tokens, :token_routes)
|
|
29
36
|
map_route(:tokens, :revoke_routes)
|
|
37
|
+
map_route(:tokens, :introspect_routes)
|
|
30
38
|
map_route(:applications, :application_routes)
|
|
31
39
|
map_route(:authorized_applications, :authorized_applications_routes)
|
|
32
40
|
map_route(:token_info, :token_info_routes)
|
|
@@ -36,20 +44,22 @@ module Doorkeeper
|
|
|
36
44
|
private
|
|
37
45
|
|
|
38
46
|
def map_route(name, method)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
unless @mapping.skipped?(name)
|
|
48
|
+
send(method, @mapping[name])
|
|
49
|
+
|
|
50
|
+
mapping[name] = @mapping[name]
|
|
51
|
+
end
|
|
42
52
|
end
|
|
43
53
|
|
|
44
54
|
def authorization_routes(mapping)
|
|
45
55
|
routes.resource(
|
|
46
56
|
:authorization,
|
|
47
57
|
path: 'authorize',
|
|
48
|
-
only: [
|
|
58
|
+
only: %i[create destroy],
|
|
49
59
|
as: mapping[:as],
|
|
50
60
|
controller: mapping[:controllers]
|
|
51
61
|
) do
|
|
52
|
-
routes.get '
|
|
62
|
+
routes.get '/native', action: :show, on: :member
|
|
53
63
|
routes.get '/', action: :new, on: :member
|
|
54
64
|
end
|
|
55
65
|
end
|
|
@@ -67,6 +77,10 @@ module Doorkeeper
|
|
|
67
77
|
routes.post 'revoke', controller: mapping[:controllers], action: :revoke
|
|
68
78
|
end
|
|
69
79
|
|
|
80
|
+
def introspect_routes(mapping)
|
|
81
|
+
routes.post 'introspect', controller: mapping[:controllers], action: :introspect
|
|
82
|
+
end
|
|
83
|
+
|
|
70
84
|
def token_info_routes(mapping)
|
|
71
85
|
routes.resource(
|
|
72
86
|
:token_info,
|
|
@@ -81,7 +95,7 @@ module Doorkeeper
|
|
|
81
95
|
end
|
|
82
96
|
|
|
83
97
|
def authorized_applications_routes(mapping)
|
|
84
|
-
routes.resources :authorized_applications, only: [
|
|
98
|
+
routes.resources :authorized_applications, only: %i[index destroy], controller: mapping[:controllers]
|
|
85
99
|
end
|
|
86
100
|
end
|
|
87
101
|
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :doorkeeper do
|
|
4
|
+
namespace :db do
|
|
5
|
+
desc 'Removes stale data from doorkeeper related database tables'
|
|
6
|
+
task cleanup: [
|
|
7
|
+
'doorkeeper:db:cleanup:revoked_tokens',
|
|
8
|
+
'doorkeeper:db:cleanup:expired_tokens',
|
|
9
|
+
'doorkeeper:db:cleanup:revoked_grants',
|
|
10
|
+
'doorkeeper:db:cleanup:expired_grants'
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
namespace :cleanup do
|
|
14
|
+
desc 'Removes stale access tokens'
|
|
15
|
+
task revoked_tokens: 'doorkeeper:setup' do
|
|
16
|
+
cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(Doorkeeper::AccessToken)
|
|
17
|
+
cleaner.clean_revoked
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
desc 'Removes expired (TTL passed) access tokens'
|
|
21
|
+
task expired_tokens: 'doorkeeper:setup' do
|
|
22
|
+
expirable_tokens = Doorkeeper::AccessToken.where(refresh_token: nil)
|
|
23
|
+
cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(expirable_tokens)
|
|
24
|
+
cleaner.clean_expired(Doorkeeper.configuration.access_token_expires_in)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
desc 'Removes stale access grants'
|
|
28
|
+
task revoked_grants: 'doorkeeper:setup' do
|
|
29
|
+
cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(Doorkeeper::AccessGrant)
|
|
30
|
+
cleaner.clean_revoked
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
desc 'Removes expired (TTL passed) access grants'
|
|
34
|
+
task expired_grants: 'doorkeeper:setup' do
|
|
35
|
+
cleaner = Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner.new(Doorkeeper::AccessGrant)
|
|
36
|
+
cleaner.clean_expired(Doorkeeper.configuration.authorization_code_expires_in)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -3,7 +3,7 @@ require 'doorkeeper/request/strategy'
|
|
|
3
3
|
module Doorkeeper
|
|
4
4
|
module Request
|
|
5
5
|
class Password < Strategy
|
|
6
|
-
delegate :credentials, :resource_owner, :parameters, to: :server
|
|
6
|
+
delegate :credentials, :resource_owner, :parameters, :client, to: :server
|
|
7
7
|
|
|
8
8
|
def request
|
|
9
9
|
@request ||= OAuth::PasswordAccessTokenRequest.new(
|
|
@@ -13,16 +13,6 @@ module Doorkeeper
|
|
|
13
13
|
parameters
|
|
14
14
|
)
|
|
15
15
|
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def client
|
|
20
|
-
if credentials
|
|
21
|
-
server.client
|
|
22
|
-
elsif parameters[:client_id]
|
|
23
|
-
server.client_via_uid
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
16
|
end
|
|
27
17
|
end
|
|
28
18
|
end
|
data/lib/doorkeeper/request.rb
CHANGED
|
@@ -7,34 +7,40 @@ require 'doorkeeper/request/token'
|
|
|
7
7
|
|
|
8
8
|
module Doorkeeper
|
|
9
9
|
module Request
|
|
10
|
-
|
|
10
|
+
class << self
|
|
11
|
+
def authorization_strategy(response_type)
|
|
12
|
+
get_strategy(response_type, authorization_response_types)
|
|
13
|
+
rescue NameError
|
|
14
|
+
raise Errors::InvalidAuthorizationStrategy
|
|
15
|
+
end
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
def token_strategy(grant_type)
|
|
18
|
+
get_strategy(grant_type, token_grant_types)
|
|
19
|
+
rescue NameError
|
|
20
|
+
raise Errors::InvalidTokenStrategy
|
|
21
|
+
end
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
raise Errors::InvalidTokenStrategy
|
|
22
|
-
end
|
|
23
|
+
def get_strategy(grant_or_request_type, available)
|
|
24
|
+
raise Errors::MissingRequestStrategy if grant_or_request_type.blank?
|
|
25
|
+
raise NameError unless available.include?(grant_or_request_type.to_s)
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
fail NameError unless available.include?(grant_or_request_type.to_s)
|
|
27
|
-
"Doorkeeper::Request::#{grant_or_request_type.to_s.camelize}".constantize
|
|
28
|
-
end
|
|
27
|
+
build_strategy_class(grant_or_request_type)
|
|
28
|
+
end
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def authorization_response_types
|
|
33
|
+
Doorkeeper.configuration.authorization_response_types
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def token_grant_types
|
|
37
|
+
Doorkeeper.configuration.token_grant_types
|
|
38
|
+
end
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
def build_strategy_class(grant_or_request_type)
|
|
41
|
+
strategy_class_name = grant_or_request_type.to_s.tr(' ', '_').camelize
|
|
42
|
+
"Doorkeeper::Request::#{strategy_class_name}".constantize
|
|
43
|
+
end
|
|
37
44
|
end
|
|
38
|
-
private_class_method :token_grant_types
|
|
39
45
|
end
|
|
40
46
|
end
|
|
@@ -6,9 +6,10 @@ module Doorkeeper
|
|
|
6
6
|
|
|
7
7
|
def validate
|
|
8
8
|
@error = nil
|
|
9
|
+
|
|
9
10
|
self.class.validations.each do |validation|
|
|
11
|
+
@error = validation[:options][:error] unless send("validate_#{validation[:attribute]}")
|
|
10
12
|
break if @error
|
|
11
|
-
@error = validation.last unless send("validate_#{validation.first}")
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
|
|
@@ -19,7 +20,7 @@ module Doorkeeper
|
|
|
19
20
|
|
|
20
21
|
module ClassMethods
|
|
21
22
|
def validate(attribute, options = {})
|
|
22
|
-
validations <<
|
|
23
|
+
validations << { attribute: attribute, options: options }
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def validations
|
data/lib/doorkeeper/version.rb
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
module Doorkeeper
|
|
2
|
-
|
|
2
|
+
def self.gem_version
|
|
3
|
+
Gem::Version.new VERSION::STRING
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
module VERSION
|
|
7
|
+
# Semantic versioning
|
|
8
|
+
MAJOR = 5
|
|
9
|
+
MINOR = 0
|
|
10
|
+
TINY = 0
|
|
11
|
+
PRE = 'rc1'
|
|
12
|
+
|
|
13
|
+
# Full version number
|
|
14
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
|
|
15
|
+
end
|
|
3
16
|
end
|
data/lib/doorkeeper.rb
CHANGED
|
@@ -8,12 +8,14 @@ require 'doorkeeper/request'
|
|
|
8
8
|
require 'doorkeeper/validations'
|
|
9
9
|
|
|
10
10
|
require 'doorkeeper/oauth/authorization/code'
|
|
11
|
+
require 'doorkeeper/oauth/authorization/context'
|
|
11
12
|
require 'doorkeeper/oauth/authorization/token'
|
|
12
13
|
require 'doorkeeper/oauth/authorization/uri_builder'
|
|
13
14
|
require 'doorkeeper/oauth/helpers/scope_checker'
|
|
14
15
|
require 'doorkeeper/oauth/helpers/uri_checker'
|
|
15
16
|
require 'doorkeeper/oauth/helpers/unique_token'
|
|
16
17
|
|
|
18
|
+
require 'doorkeeper/oauth'
|
|
17
19
|
require 'doorkeeper/oauth/scopes'
|
|
18
20
|
require 'doorkeeper/oauth/error'
|
|
19
21
|
require 'doorkeeper/oauth/base_response'
|
|
@@ -30,9 +32,11 @@ require 'doorkeeper/oauth/code_request'
|
|
|
30
32
|
require 'doorkeeper/oauth/token_request'
|
|
31
33
|
require 'doorkeeper/oauth/client'
|
|
32
34
|
require 'doorkeeper/oauth/token'
|
|
35
|
+
require 'doorkeeper/oauth/token_introspection'
|
|
33
36
|
require 'doorkeeper/oauth/invalid_token_response'
|
|
34
37
|
require 'doorkeeper/oauth/forbidden_token_response'
|
|
35
38
|
|
|
39
|
+
require 'doorkeeper/models/concerns/orderable'
|
|
36
40
|
require 'doorkeeper/models/concerns/scopes'
|
|
37
41
|
require 'doorkeeper/models/concerns/expirable'
|
|
38
42
|
require 'doorkeeper/models/concerns/revocable'
|
|
@@ -47,26 +51,11 @@ require 'doorkeeper/helpers/controller'
|
|
|
47
51
|
require 'doorkeeper/rails/routes'
|
|
48
52
|
require 'doorkeeper/rails/helpers'
|
|
49
53
|
|
|
50
|
-
require 'doorkeeper/
|
|
54
|
+
require 'doorkeeper/rake'
|
|
51
55
|
|
|
52
|
-
require '
|
|
56
|
+
require 'doorkeeper/orm/active_record'
|
|
53
57
|
|
|
54
58
|
module Doorkeeper
|
|
55
|
-
def self.configured?
|
|
56
|
-
ActiveSupport::Deprecation.warn "Method `Doorkeeper#configured?` has been deprecated without replacement."
|
|
57
|
-
@config.present?
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def self.database_installed?
|
|
61
|
-
ActiveSupport::Deprecation.warn "Method `Doorkeeper#database_installed?` has been deprecated without replacement."
|
|
62
|
-
[AccessToken, AccessGrant, Application].all?(&:table_exists?)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def self.installed?
|
|
66
|
-
ActiveSupport::Deprecation.warn "Method `Doorkeeper#installed?` has been deprecated without replacement."
|
|
67
|
-
configured? && database_installed?
|
|
68
|
-
end
|
|
69
|
-
|
|
70
59
|
def self.authenticate(request, methods = Doorkeeper.configuration.access_token_methods)
|
|
71
60
|
OAuth::Token.authenticate(request, *methods)
|
|
72
61
|
end
|
|
@@ -1,18 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
1
4
|
require 'rails/generators/active_record'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
module Doorkeeper
|
|
7
|
+
class ApplicationOwnerGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Provide support for client application ownership.'
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
def application_owner
|
|
13
|
+
migration_template(
|
|
14
|
+
'add_owner_to_application_migration.rb.erb',
|
|
15
|
+
'db/migrate/add_owner_to_application.rb',
|
|
16
|
+
migration_version: migration_version
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.next_migration_number(dirname)
|
|
21
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
def migration_version
|
|
27
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
|
28
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
17
31
|
end
|
|
18
32
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
require 'rails/generators/active_record'
|
|
5
|
+
|
|
6
|
+
module Doorkeeper
|
|
7
|
+
class ConfidentialApplicationsGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Add confidential column to Doorkeeper applications'
|
|
11
|
+
|
|
12
|
+
def pkce
|
|
13
|
+
migration_template(
|
|
14
|
+
'add_confidential_to_applications.rb.erb',
|
|
15
|
+
'db/migrate/add_confidential_to_applications.rb',
|
|
16
|
+
migration_version: migration_version
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.next_migration_number(dirname)
|
|
21
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def migration_version
|
|
27
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
|
28
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
include Rails::Generators::Migration
|
|
3
|
-
source_root File.expand_path('../templates', __FILE__)
|
|
4
|
-
desc 'Installs Doorkeeper.'
|
|
1
|
+
# frozen_string_literal: true
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
require 'rails/generators/active_record'
|
|
5
|
+
|
|
6
|
+
module Doorkeeper
|
|
7
|
+
class InstallGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Installs Doorkeeper.'
|
|
11
|
+
|
|
12
|
+
def install
|
|
13
|
+
template 'initializer.rb', 'config/initializers/doorkeeper.rb'
|
|
14
|
+
copy_file File.expand_path('../../../config/locales/en.yml', __dir__),
|
|
15
|
+
'config/locales/doorkeeper.en.yml'
|
|
16
|
+
route 'use_doorkeeper'
|
|
17
|
+
readme 'README'
|
|
18
|
+
end
|
|
11
19
|
end
|
|
12
20
|
end
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
1
4
|
require 'rails/generators/active_record'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
module Doorkeeper
|
|
7
|
+
class MigrationGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Installs Doorkeeper migration file.'
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
def install
|
|
13
|
+
migration_template(
|
|
14
|
+
'migration.rb.erb',
|
|
15
|
+
'db/migrate/create_doorkeeper_tables.rb',
|
|
16
|
+
migration_version: migration_version
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.next_migration_number(dirname)
|
|
21
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
11
25
|
|
|
12
|
-
|
|
13
|
-
|
|
26
|
+
def migration_version
|
|
27
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
|
28
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
14
31
|
end
|
|
15
32
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
require 'rails/generators/active_record'
|
|
5
|
+
|
|
6
|
+
module Doorkeeper
|
|
7
|
+
class PkceGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Provide support for PKCE.'
|
|
11
|
+
|
|
12
|
+
def pkce
|
|
13
|
+
migration_template(
|
|
14
|
+
'enable_pkce_migration.rb.erb',
|
|
15
|
+
'db/migrate/enable_pkce.rb',
|
|
16
|
+
migration_version: migration_version
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.next_migration_number(dirname)
|
|
21
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def migration_version
|
|
27
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
|
28
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|