doorkeeper 4.2.5 → 5.0.0
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/.gitlab-ci.yml +16 -0
- data/.hound.yml +2 -13
- data/.rubocop.yml +17 -0
- data/.travis.yml +19 -4
- data/Appraisals +8 -4
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +1 -1
- data/NEWS.md +115 -0
- data/README.md +175 -39
- data/RELEASING.md +5 -12
- data/Rakefile +6 -0
- data/SECURITY.md +15 -0
- data/UPGRADE.md +2 -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 +19 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +24 -17
- 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 +5 -1
- 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 +19 -6
- data/doorkeeper.gemspec +20 -20
- 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 +17 -0
- data/lib/doorkeeper/config.rb +123 -71
- data/lib/doorkeeper/engine.rb +7 -3
- data/lib/doorkeeper/errors.rb +20 -5
- data/lib/doorkeeper/grape/helpers.rb +14 -9
- data/lib/doorkeeper/helpers/controller.rb +16 -22
- data/lib/doorkeeper/models/access_grant_mixin.rb +67 -23
- data/lib/doorkeeper/models/access_token_mixin.rb +54 -55
- 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 +46 -20
- data/lib/doorkeeper/oauth/authorization_code_request.rb +33 -3
- data/lib/doorkeeper/oauth/base_request.rb +23 -7
- data/lib/doorkeeper/oauth/client/credentials.rb +6 -4
- data/lib/doorkeeper/oauth/client.rb +2 -4
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -1
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -3
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -6
- data/lib/doorkeeper/oauth/client_credentials_request.rb +0 -4
- 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 +45 -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/authorization_code.rb +0 -2
- data/lib/doorkeeper/request/client_credentials.rb +0 -2
- data/lib/doorkeeper/request/code.rb +0 -2
- data/lib/doorkeeper/request/password.rb +1 -13
- data/lib/doorkeeper/request/refresh_token.rb +0 -2
- data/lib/doorkeeper/request/token.rb +0 -2
- data/lib/doorkeeper/request.rb +29 -30
- data/lib/doorkeeper/validations.rb +3 -2
- data/lib/doorkeeper/version.rb +14 -1
- data/lib/doorkeeper.rb +21 -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 +104 -12
- 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 +304 -27
- 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 +201 -17
- 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 +23 -2
- 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 +199 -22
- data/spec/lib/doorkeeper_spec.rb +1 -126
- data/spec/lib/models/expirable_spec.rb +0 -4
- 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 +43 -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 +45 -2
- data/spec/models/doorkeeper/access_token_spec.rb +132 -64
- data/spec/models/doorkeeper/application_spec.rb +114 -23
- data/spec/requests/applications/applications_request_spec.rb +139 -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 +12 -2
- data/spec/requests/flows/authorization_code_spec.rb +199 -2
- 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 -64
- 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 +18 -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 +75 -33
- data/spec/controllers/application_metal_controller.rb +0 -10
- data/spec/support/dependencies/factory_girl.rb +0 -2
data/lib/doorkeeper.rb
CHANGED
|
@@ -2,18 +2,28 @@ require 'doorkeeper/version'
|
|
|
2
2
|
require 'doorkeeper/engine'
|
|
3
3
|
require 'doorkeeper/config'
|
|
4
4
|
|
|
5
|
+
require 'doorkeeper/request/strategy'
|
|
6
|
+
require 'doorkeeper/request/authorization_code'
|
|
7
|
+
require 'doorkeeper/request/client_credentials'
|
|
8
|
+
require 'doorkeeper/request/code'
|
|
9
|
+
require 'doorkeeper/request/password'
|
|
10
|
+
require 'doorkeeper/request/refresh_token'
|
|
11
|
+
require 'doorkeeper/request/token'
|
|
12
|
+
|
|
5
13
|
require 'doorkeeper/errors'
|
|
6
14
|
require 'doorkeeper/server'
|
|
7
15
|
require 'doorkeeper/request'
|
|
8
16
|
require 'doorkeeper/validations'
|
|
9
17
|
|
|
10
18
|
require 'doorkeeper/oauth/authorization/code'
|
|
19
|
+
require 'doorkeeper/oauth/authorization/context'
|
|
11
20
|
require 'doorkeeper/oauth/authorization/token'
|
|
12
21
|
require 'doorkeeper/oauth/authorization/uri_builder'
|
|
13
22
|
require 'doorkeeper/oauth/helpers/scope_checker'
|
|
14
23
|
require 'doorkeeper/oauth/helpers/uri_checker'
|
|
15
24
|
require 'doorkeeper/oauth/helpers/unique_token'
|
|
16
25
|
|
|
26
|
+
require 'doorkeeper/oauth'
|
|
17
27
|
require 'doorkeeper/oauth/scopes'
|
|
18
28
|
require 'doorkeeper/oauth/error'
|
|
19
29
|
require 'doorkeeper/oauth/base_response'
|
|
@@ -25,14 +35,23 @@ require 'doorkeeper/oauth/base_request'
|
|
|
25
35
|
require 'doorkeeper/oauth/authorization_code_request'
|
|
26
36
|
require 'doorkeeper/oauth/refresh_token_request'
|
|
27
37
|
require 'doorkeeper/oauth/password_access_token_request'
|
|
38
|
+
|
|
39
|
+
require 'doorkeeper/oauth/client_credentials/validation'
|
|
40
|
+
require 'doorkeeper/oauth/client_credentials/creator'
|
|
41
|
+
require 'doorkeeper/oauth/client_credentials/issuer'
|
|
42
|
+
require 'doorkeeper/oauth/client_credentials/validation'
|
|
43
|
+
require 'doorkeeper/oauth/client/credentials'
|
|
44
|
+
|
|
28
45
|
require 'doorkeeper/oauth/client_credentials_request'
|
|
29
46
|
require 'doorkeeper/oauth/code_request'
|
|
30
47
|
require 'doorkeeper/oauth/token_request'
|
|
31
48
|
require 'doorkeeper/oauth/client'
|
|
32
49
|
require 'doorkeeper/oauth/token'
|
|
50
|
+
require 'doorkeeper/oauth/token_introspection'
|
|
33
51
|
require 'doorkeeper/oauth/invalid_token_response'
|
|
34
52
|
require 'doorkeeper/oauth/forbidden_token_response'
|
|
35
53
|
|
|
54
|
+
require 'doorkeeper/models/concerns/orderable'
|
|
36
55
|
require 'doorkeeper/models/concerns/scopes'
|
|
37
56
|
require 'doorkeeper/models/concerns/expirable'
|
|
38
57
|
require 'doorkeeper/models/concerns/revocable'
|
|
@@ -47,26 +66,11 @@ require 'doorkeeper/helpers/controller'
|
|
|
47
66
|
require 'doorkeeper/rails/routes'
|
|
48
67
|
require 'doorkeeper/rails/helpers'
|
|
49
68
|
|
|
50
|
-
require 'doorkeeper/
|
|
69
|
+
require 'doorkeeper/rake'
|
|
51
70
|
|
|
52
|
-
require '
|
|
71
|
+
require 'doorkeeper/orm/active_record'
|
|
53
72
|
|
|
54
73
|
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
74
|
def self.authenticate(request, methods = Doorkeeper.configuration.access_token_methods)
|
|
71
75
|
OAuth::Token.authenticate(request, *methods)
|
|
72
76
|
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
|
|
@@ -1,29 +1,40 @@
|
|
|
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 PreviousRefreshTokenGenerator < ::Rails::Generators::Base
|
|
8
|
+
include ::Rails::Generators::Migration
|
|
9
|
+
source_root File.expand_path('templates', __dir__)
|
|
10
|
+
desc 'Support revoke refresh token on access token use'
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
def self.next_migration_number(path)
|
|
13
|
+
ActiveRecord::Generators::Base.next_migration_number(path)
|
|
14
|
+
end
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
def previous_refresh_token
|
|
17
|
+
if no_previous_refresh_token_column?
|
|
18
|
+
migration_template(
|
|
19
|
+
'add_previous_refresh_token_to_access_tokens.rb.erb',
|
|
20
|
+
'db/migrate/add_previous_refresh_token_to_access_tokens.rb'
|
|
21
|
+
)
|
|
22
|
+
end
|
|
18
23
|
end
|
|
19
|
-
end
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
private
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
def migration_version
|
|
28
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
|
29
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def no_previous_refresh_token_column?
|
|
34
|
+
!ActiveRecord::Base.connection.column_exists?(
|
|
35
|
+
:oauth_access_tokens,
|
|
36
|
+
:previous_refresh_token
|
|
37
|
+
)
|
|
38
|
+
end
|
|
28
39
|
end
|
|
29
40
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class AddOwnerToApplication < ActiveRecord::Migration
|
|
1
|
+
class AddOwnerToApplication < ActiveRecord::Migration<%= migration_version %>
|
|
2
2
|
def change
|
|
3
3
|
add_column :oauth_applications, :owner_id, :integer, null: true
|
|
4
4
|
add_column :oauth_applications, :owner_type, :string, null: true
|
|
@@ -4,69 +4,120 @@ Doorkeeper.configure do
|
|
|
4
4
|
|
|
5
5
|
# This block will be called to check whether the resource owner is authenticated or not.
|
|
6
6
|
resource_owner_authenticator do
|
|
7
|
-
|
|
7
|
+
raise "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"
|
|
8
8
|
# Put your resource owner authentication logic here.
|
|
9
9
|
# Example implementation:
|
|
10
10
|
# User.find_by_id(session[:user_id]) || redirect_to(new_user_session_url)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
# If you
|
|
13
|
+
# If you didn't skip applications controller from Doorkeeper routes in your application routes.rb
|
|
14
|
+
# file then you need to declare this block in order to restrict access to the web interface for
|
|
15
|
+
# adding oauth authorized applications. In other case it will return 403 Forbidden response
|
|
16
|
+
# every time somebody will try to access the admin web interface.
|
|
17
|
+
#
|
|
14
18
|
# admin_authenticator do
|
|
15
19
|
# # Put your admin authentication logic here.
|
|
16
20
|
# # Example implementation:
|
|
17
|
-
#
|
|
21
|
+
#
|
|
22
|
+
# if current_user
|
|
23
|
+
# head :forbidden unless current_user.admin?
|
|
24
|
+
# else
|
|
25
|
+
# redirect_to sign_in_url
|
|
26
|
+
# end
|
|
18
27
|
# end
|
|
19
28
|
|
|
29
|
+
# If you are planning to use Doorkeeper in Rails 5 API-only application, then you might
|
|
30
|
+
# want to use API mode that will skip all the views management and change the way how
|
|
31
|
+
# Doorkeeper responds to a requests.
|
|
32
|
+
#
|
|
33
|
+
# api_only
|
|
34
|
+
|
|
35
|
+
# Enforce token request content type to application/x-www-form-urlencoded.
|
|
36
|
+
# It is not enabled by default to not break prior versions of the gem.
|
|
37
|
+
#
|
|
38
|
+
# enforce_content_type
|
|
39
|
+
|
|
20
40
|
# Authorization Code expiration time (default 10 minutes).
|
|
41
|
+
#
|
|
21
42
|
# authorization_code_expires_in 10.minutes
|
|
22
43
|
|
|
23
44
|
# Access token expiration time (default 2 hours).
|
|
24
45
|
# If you want to disable expiration, set this to nil.
|
|
46
|
+
#
|
|
25
47
|
# access_token_expires_in 2.hours
|
|
26
48
|
|
|
27
|
-
# Assign
|
|
28
|
-
#
|
|
29
|
-
#
|
|
49
|
+
# Assign custom TTL for access tokens. Will be used instead of access_token_expires_in
|
|
50
|
+
# option if defined. `context` has the following properties available
|
|
51
|
+
#
|
|
52
|
+
# `client` - the OAuth client application (see Doorkeeper::OAuth::Client)
|
|
53
|
+
# `grant_type` - the grant type of the request (see Doorkeeper::OAuth)
|
|
54
|
+
# `scopes` - the requested scopes (see Doorkeeper::OAuth::Scopes)
|
|
55
|
+
#
|
|
56
|
+
# custom_access_token_expires_in do |context|
|
|
57
|
+
# context.client.application.additional_settings.implicit_oauth_expiration
|
|
30
58
|
# end
|
|
31
59
|
|
|
32
60
|
# Use a custom class for generating the access token.
|
|
33
|
-
# https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
|
|
61
|
+
# See https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
|
|
62
|
+
#
|
|
34
63
|
# access_token_generator '::Doorkeeper::JWT'
|
|
35
64
|
|
|
36
65
|
# The controller Doorkeeper::ApplicationController inherits from.
|
|
37
66
|
# Defaults to ActionController::Base.
|
|
38
|
-
# https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
|
|
67
|
+
# See https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
|
|
68
|
+
#
|
|
39
69
|
# base_controller 'ApplicationController'
|
|
40
70
|
|
|
41
71
|
# Reuse access token for the same resource owner within an application (disabled by default)
|
|
42
72
|
# Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
|
|
73
|
+
#
|
|
43
74
|
# reuse_access_token
|
|
44
75
|
|
|
45
|
-
# Issue access tokens with refresh token (disabled by default)
|
|
76
|
+
# Issue access tokens with refresh token (disabled by default), you may also
|
|
77
|
+
# pass a block which accepts `context` to customize when to give a refresh
|
|
78
|
+
# token or not. Similar to `custom_access_token_expires_in`, `context` has
|
|
79
|
+
# the properties:
|
|
80
|
+
#
|
|
81
|
+
# `client` - the OAuth client application (see Doorkeeper::OAuth::Client)
|
|
82
|
+
# `grant_type` - the grant type of the request (see Doorkeeper::OAuth)
|
|
83
|
+
# `scopes` - the requested scopes (see Doorkeeper::OAuth::Scopes)
|
|
84
|
+
#
|
|
46
85
|
# use_refresh_token
|
|
47
86
|
|
|
87
|
+
# Forbids creating/updating applications with arbitrary scopes that are
|
|
88
|
+
# not in configuration, i.e. `default_scopes` or `optional_scopes`.
|
|
89
|
+
# (disabled by default)
|
|
90
|
+
#
|
|
91
|
+
# enforce_configured_scopes
|
|
92
|
+
|
|
48
93
|
# Provide support for an owner to be assigned to each registered application (disabled by default)
|
|
49
94
|
# Optional parameter confirmation: true (default false) if you want to enforce ownership of
|
|
50
95
|
# a registered application
|
|
51
96
|
# Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
|
|
97
|
+
#
|
|
52
98
|
# enable_application_owner confirmation: false
|
|
53
99
|
|
|
54
100
|
# Define access token scopes for your provider
|
|
55
101
|
# For more information go to
|
|
56
102
|
# https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes
|
|
103
|
+
#
|
|
57
104
|
# default_scopes :public
|
|
58
105
|
# optional_scopes :write, :update
|
|
59
106
|
|
|
60
107
|
# Change the way client credentials are retrieved from the request object.
|
|
61
108
|
# By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
|
|
62
109
|
# falls back to the `:client_id` and `:client_secret` params from the `params` object.
|
|
63
|
-
# Check out
|
|
110
|
+
# Check out https://github.com/doorkeeper-gem/doorkeeper/wiki/Changing-how-clients-are-authenticated
|
|
111
|
+
# for more information on customization
|
|
112
|
+
#
|
|
64
113
|
# client_credentials :from_basic, :from_params
|
|
65
114
|
|
|
66
115
|
# Change the way access token is authenticated from the request object.
|
|
67
116
|
# By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
|
|
68
117
|
# falls back to the `:access_token` or `:bearer_token` params from the `params` object.
|
|
69
|
-
# Check out
|
|
118
|
+
# Check out https://github.com/doorkeeper-gem/doorkeeper/wiki/Changing-how-clients-are-authenticated
|
|
119
|
+
# for more information on customization
|
|
120
|
+
#
|
|
70
121
|
# access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
|
|
71
122
|
|
|
72
123
|
# Change the native redirect uri for client apps
|
|
@@ -80,7 +131,21 @@ Doorkeeper.configure do
|
|
|
80
131
|
# by default in non-development environments). OAuth2 delegates security in
|
|
81
132
|
# communication to the HTTPS protocol so it is wise to keep this enabled.
|
|
82
133
|
#
|
|
134
|
+
# Callable objects such as proc, lambda, block or any object that responds to
|
|
135
|
+
# #call can be used in order to allow conditional checks (to allow non-SSL
|
|
136
|
+
# redirects to localhost for example).
|
|
137
|
+
#
|
|
83
138
|
# force_ssl_in_redirect_uri !Rails.env.development?
|
|
139
|
+
#
|
|
140
|
+
# force_ssl_in_redirect_uri { |uri| uri.host != 'localhost' }
|
|
141
|
+
|
|
142
|
+
# Specify what redirect URI's you want to block during Application creation.
|
|
143
|
+
# Any redirect URI is whitelisted by default.
|
|
144
|
+
#
|
|
145
|
+
# You can use this option in order to forbid URI's with 'javascript' scheme
|
|
146
|
+
# for example.
|
|
147
|
+
#
|
|
148
|
+
# forbid_redirect_uri { |uri| uri.scheme.to_s.downcase == 'javascript' }
|
|
84
149
|
|
|
85
150
|
# Specify what grant flows are enabled in array of Strings. The valid
|
|
86
151
|
# strings and the flows they enable are:
|
|
@@ -98,15 +163,42 @@ Doorkeeper.configure do
|
|
|
98
163
|
# http://tools.ietf.org/html/rfc6819#section-4.4.2
|
|
99
164
|
# http://tools.ietf.org/html/rfc6819#section-4.4.3
|
|
100
165
|
#
|
|
101
|
-
# grant_flows %w
|
|
166
|
+
# grant_flows %w[authorization_code client_credentials]
|
|
167
|
+
|
|
168
|
+
# Hook into the strategies' request & response life-cycle in case your
|
|
169
|
+
# application needs advanced customization or logging:
|
|
170
|
+
#
|
|
171
|
+
# before_successful_strategy_response do |request|
|
|
172
|
+
# puts "BEFORE HOOK FIRED! #{request}"
|
|
173
|
+
# end
|
|
174
|
+
#
|
|
175
|
+
# after_successful_strategy_response do |request, response|
|
|
176
|
+
# puts "AFTER HOOK FIRED! #{request}, #{response}"
|
|
177
|
+
# end
|
|
178
|
+
|
|
179
|
+
# Hook into Authorization flow in order to implement Single Sign Out
|
|
180
|
+
# or add ny other functionality.
|
|
181
|
+
#
|
|
182
|
+
# before_successful_authorization do |controller|
|
|
183
|
+
# Rails.logger.info(params.inspect)
|
|
184
|
+
# end
|
|
185
|
+
#
|
|
186
|
+
# after_successful_authorization do |controller|
|
|
187
|
+
# controller.session[:logout_urls] <<
|
|
188
|
+
# Doorkeeper::Application
|
|
189
|
+
# .find_by(controller.request.params.slice(:redirect_uri))
|
|
190
|
+
# .logout_uri
|
|
191
|
+
# end
|
|
102
192
|
|
|
103
193
|
# Under some circumstances you might want to have applications auto-approved,
|
|
104
194
|
# so that the user skips the authorization step.
|
|
105
195
|
# For example if dealing with a trusted application.
|
|
196
|
+
#
|
|
106
197
|
# skip_authorization do |resource_owner, client|
|
|
107
198
|
# client.superapp? or resource_owner.admin?
|
|
108
199
|
# end
|
|
109
200
|
|
|
110
201
|
# WWW-Authenticate Realm (default "Doorkeeper").
|
|
202
|
+
#
|
|
111
203
|
# realm "Doorkeeper"
|
|
112
204
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
1
|
+
class CreateDoorkeeperTables < ActiveRecord::Migration<%= migration_version %>
|
|
2
2
|
def change
|
|
3
3
|
create_table :oauth_applications do |t|
|
|
4
4
|
t.string :name, null: false
|
|
@@ -6,6 +6,7 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
|
|
|
6
6
|
t.string :secret, null: false
|
|
7
7
|
t.text :redirect_uri, null: false
|
|
8
8
|
t.string :scopes, null: false, default: ''
|
|
9
|
+
t.boolean :confidential, null: false, default: true
|
|
9
10
|
t.timestamps null: false
|
|
10
11
|
end
|
|
11
12
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Doorkeeper
|
|
2
4
|
module Generators
|
|
3
5
|
class ViewsGenerator < ::Rails::Generators::Base
|
|
4
|
-
source_root File.expand_path('
|
|
6
|
+
source_root File.expand_path('../../../app/views', __dir__)
|
|
5
7
|
|
|
6
8
|
desc 'Copies default Doorkeeper views and layouts to your application.'
|
|
7
9
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper_integration'
|
|
4
|
+
|
|
5
|
+
describe Doorkeeper::ApplicationMetalController do
|
|
6
|
+
controller(Doorkeeper::ApplicationMetalController) do
|
|
7
|
+
def index
|
|
8
|
+
render json: {}, status: 200
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "lazy run hooks" do
|
|
13
|
+
i = 0
|
|
14
|
+
ActiveSupport.on_load(:doorkeeper_metal_controller) { i += 1 }
|
|
15
|
+
|
|
16
|
+
expect(i).to eq 1
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe 'enforce_content_type' do
|
|
20
|
+
before { allow(Doorkeeper.configuration).to receive(:enforce_content_type).and_return(flag) }
|
|
21
|
+
|
|
22
|
+
context 'enabled' do
|
|
23
|
+
let(:flag) { true }
|
|
24
|
+
|
|
25
|
+
it '200 for the correct media type' do
|
|
26
|
+
get :index, params: {}, as: :url_encoded_form
|
|
27
|
+
expect(response).to have_http_status 200
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'returns a 415 for an incorrect media type' do
|
|
31
|
+
get :index, as: :json
|
|
32
|
+
expect(response).to have_http_status 415
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'disabled' do
|
|
37
|
+
let(:flag) { false }
|
|
38
|
+
|
|
39
|
+
it 'returns a 200 for the correct media type' do
|
|
40
|
+
get :index, as: :url_encoded_form
|
|
41
|
+
expect(response).to have_http_status 200
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'returns a 200 for an incorrect media type' do
|
|
45
|
+
get :index, as: :json
|
|
46
|
+
expect(response).to have_http_status 200
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|