doorkeeper 4.4.3 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of doorkeeper might be problematic. Click here for more details.

Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +16 -0
  4. data/.travis.yml +2 -0
  5. data/Appraisals +2 -2
  6. data/Gemfile +1 -1
  7. data/NEWS.md +61 -8
  8. data/README.md +92 -9
  9. data/Rakefile +6 -0
  10. data/UPGRADE.md +2 -0
  11. data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
  12. data/app/controllers/doorkeeper/application_controller.rb +4 -3
  13. data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
  14. data/app/controllers/doorkeeper/applications_controller.rb +42 -22
  15. data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
  16. data/app/controllers/doorkeeper/authorized_applications_controller.rb +19 -2
  17. data/app/controllers/doorkeeper/tokens_controller.rb +2 -6
  18. data/app/helpers/doorkeeper/dashboard_helper.rb +7 -7
  19. data/app/validators/redirect_uri_validator.rb +3 -2
  20. data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
  21. data/app/views/doorkeeper/applications/_form.html.erb +25 -24
  22. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  23. data/app/views/doorkeeper/applications/index.html.erb +17 -7
  24. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  25. data/app/views/doorkeeper/applications/show.html.erb +6 -6
  26. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  27. data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
  28. data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
  29. data/config/locales/en.yml +10 -1
  30. data/doorkeeper.gemspec +18 -20
  31. data/gemfiles/rails_5_2.gemfile +1 -1
  32. data/gemfiles/rails_master.gemfile +4 -1
  33. data/lib/doorkeeper/config.rb +75 -39
  34. data/lib/doorkeeper/engine.rb +4 -0
  35. data/lib/doorkeeper/errors.rb +2 -5
  36. data/lib/doorkeeper/grape/helpers.rb +1 -1
  37. data/lib/doorkeeper/helpers/controller.rb +7 -2
  38. data/lib/doorkeeper/models/access_grant_mixin.rb +71 -0
  39. data/lib/doorkeeper/models/access_token_mixin.rb +39 -22
  40. data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
  41. data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
  42. data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
  43. data/lib/doorkeeper/oauth/authorization/token.rb +36 -14
  44. data/lib/doorkeeper/oauth/authorization_code_request.rb +27 -2
  45. data/lib/doorkeeper/oauth/base_request.rb +20 -9
  46. data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
  47. data/lib/doorkeeper/oauth/client.rb +0 -2
  48. data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -1
  49. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -3
  50. data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -6
  51. data/lib/doorkeeper/oauth/client_credentials_request.rb +0 -4
  52. data/lib/doorkeeper/oauth/error_response.rb +11 -3
  53. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
  54. data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -4
  55. data/lib/doorkeeper/oauth/pre_authorization.rb +41 -11
  56. data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -1
  57. data/lib/doorkeeper/oauth/scopes.rb +1 -1
  58. data/lib/doorkeeper/oauth/token.rb +5 -2
  59. data/lib/doorkeeper/oauth/token_introspection.rb +2 -2
  60. data/lib/doorkeeper/oauth/token_response.rb +4 -2
  61. data/lib/doorkeeper/oauth.rb +13 -0
  62. data/lib/doorkeeper/orm/active_record/application.rb +22 -14
  63. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
  64. data/lib/doorkeeper/orm/active_record.rb +2 -0
  65. data/lib/doorkeeper/rails/helpers.rb +2 -4
  66. data/lib/doorkeeper/rails/routes.rb +14 -6
  67. data/lib/doorkeeper/rake/db.rake +40 -0
  68. data/lib/doorkeeper/rake/setup.rake +6 -0
  69. data/lib/doorkeeper/rake.rb +14 -0
  70. data/lib/doorkeeper/request/authorization_code.rb +0 -2
  71. data/lib/doorkeeper/request/client_credentials.rb +0 -2
  72. data/lib/doorkeeper/request/code.rb +0 -2
  73. data/lib/doorkeeper/request/password.rb +0 -2
  74. data/lib/doorkeeper/request/refresh_token.rb +0 -2
  75. data/lib/doorkeeper/request/token.rb +0 -2
  76. data/lib/doorkeeper/request.rb +28 -35
  77. data/lib/doorkeeper/version.rb +5 -25
  78. data/lib/doorkeeper.rb +19 -17
  79. data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
  80. data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
  81. data/lib/generators/doorkeeper/install_generator.rb +17 -9
  82. data/lib/generators/doorkeeper/migration_generator.rb +23 -18
  83. data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
  84. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
  85. data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
  86. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
  87. data/lib/generators/doorkeeper/templates/initializer.rb +76 -11
  88. data/lib/generators/doorkeeper/views_generator.rb +3 -1
  89. data/spec/controllers/application_metal_controller_spec.rb +50 -0
  90. data/spec/controllers/applications_controller_spec.rb +126 -13
  91. data/spec/controllers/authorizations_controller_spec.rb +277 -47
  92. data/spec/controllers/protected_resources_controller_spec.rb +16 -16
  93. data/spec/controllers/token_info_controller_spec.rb +4 -12
  94. data/spec/controllers/tokens_controller_spec.rb +13 -15
  95. data/spec/dummy/app/assets/config/manifest.js +2 -0
  96. data/spec/dummy/config/environments/test.rb +4 -5
  97. data/spec/dummy/config/initializers/doorkeeper.rb +10 -5
  98. data/spec/dummy/config/initializers/new_framework_defaults.rb +4 -0
  99. data/spec/dummy/config/routes.rb +3 -42
  100. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
  101. data/spec/dummy/db/migrate/{20180210183654_add_confidential_to_application.rb → 20180210183654_add_confidential_to_applications.rb} +1 -1
  102. data/spec/dummy/db/schema.rb +36 -36
  103. data/spec/generators/application_owner_generator_spec.rb +1 -1
  104. data/spec/generators/confidential_applications_generator_spec.rb +45 -0
  105. data/spec/generators/install_generator_spec.rb +1 -1
  106. data/spec/generators/migration_generator_spec.rb +1 -1
  107. data/spec/generators/pkce_generator_spec.rb +43 -0
  108. data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
  109. data/spec/generators/views_generator_spec.rb +1 -1
  110. data/spec/grape/grape_integration_spec.rb +1 -1
  111. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  112. data/spec/lib/config_spec.rb +80 -31
  113. data/spec/lib/doorkeeper_spec.rb +1 -126
  114. data/spec/lib/models/expirable_spec.rb +0 -3
  115. data/spec/lib/models/revocable_spec.rb +0 -2
  116. data/spec/lib/models/scopes_spec.rb +0 -4
  117. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
  118. data/spec/lib/oauth/authorization_code_request_spec.rb +9 -2
  119. data/spec/lib/oauth/base_request_spec.rb +40 -2
  120. data/spec/lib/oauth/base_response_spec.rb +1 -1
  121. data/spec/lib/oauth/client/credentials_spec.rb +1 -3
  122. data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
  123. data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
  124. data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
  125. data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
  126. data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
  127. data/spec/lib/oauth/client_spec.rb +0 -3
  128. data/spec/lib/oauth/code_request_spec.rb +4 -2
  129. data/spec/lib/oauth/error_response_spec.rb +0 -3
  130. data/spec/lib/oauth/error_spec.rb +0 -2
  131. data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
  132. data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
  133. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
  134. data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -7
  135. data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
  136. data/spec/lib/oauth/password_access_token_request_spec.rb +37 -2
  137. data/spec/lib/oauth/pre_authorization_spec.rb +33 -4
  138. data/spec/lib/oauth/refresh_token_request_spec.rb +11 -7
  139. data/spec/lib/oauth/scopes_spec.rb +0 -3
  140. data/spec/lib/oauth/token_request_spec.rb +4 -5
  141. data/spec/lib/oauth/token_response_spec.rb +0 -1
  142. data/spec/lib/oauth/token_spec.rb +37 -14
  143. data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
  144. data/spec/lib/request/strategy_spec.rb +0 -1
  145. data/spec/lib/server_spec.rb +1 -1
  146. data/spec/models/doorkeeper/access_grant_spec.rb +44 -1
  147. data/spec/models/doorkeeper/access_token_spec.rb +66 -22
  148. data/spec/models/doorkeeper/application_spec.rb +14 -47
  149. data/spec/requests/applications/applications_request_spec.rb +134 -1
  150. data/spec/requests/applications/authorized_applications_spec.rb +1 -1
  151. data/spec/requests/endpoints/authorization_spec.rb +1 -1
  152. data/spec/requests/endpoints/token_spec.rb +7 -5
  153. data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
  154. data/spec/requests/flows/authorization_code_spec.rb +197 -1
  155. data/spec/requests/flows/client_credentials_spec.rb +46 -6
  156. data/spec/requests/flows/implicit_grant_errors_spec.rb +1 -1
  157. data/spec/requests/flows/implicit_grant_spec.rb +38 -11
  158. data/spec/requests/flows/password_spec.rb +56 -2
  159. data/spec/requests/flows/refresh_token_spec.rb +2 -2
  160. data/spec/requests/flows/revoke_token_spec.rb +11 -11
  161. data/spec/requests/flows/skip_authorization_spec.rb +16 -11
  162. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  163. data/spec/requests/protected_resources/private_api_spec.rb +1 -1
  164. data/spec/routing/custom_controller_routes_spec.rb +59 -7
  165. data/spec/routing/default_routes_spec.rb +2 -2
  166. data/spec/routing/scoped_routes_spec.rb +16 -2
  167. data/spec/spec_helper.rb +54 -3
  168. data/spec/spec_helper_integration.rb +2 -74
  169. data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
  170. data/spec/support/doorkeeper_rspec.rb +19 -0
  171. data/spec/support/helpers/authorization_request_helper.rb +4 -4
  172. data/spec/support/helpers/request_spec_helper.rb +10 -2
  173. data/spec/support/helpers/url_helper.rb +7 -3
  174. data/spec/support/http_method_shim.rb +12 -16
  175. data/spec/validators/redirect_uri_validator_spec.rb +7 -1
  176. data/spec/version/version_spec.rb +3 -3
  177. data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
  178. metadata +37 -33
  179. data/lib/generators/doorkeeper/add_client_confidentiality_generator.rb +0 -31
  180. data/lib/generators/doorkeeper/templates/add_confidential_to_application_migration.rb.erb +0 -11
  181. data/spec/controllers/application_metal_controller.rb +0 -10
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,6 +35,13 @@ 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'
@@ -49,26 +66,11 @@ require 'doorkeeper/helpers/controller'
49
66
  require 'doorkeeper/rails/routes'
50
67
  require 'doorkeeper/rails/helpers'
51
68
 
52
- require 'doorkeeper/orm/active_record'
69
+ require 'doorkeeper/rake'
53
70
 
54
- require 'active_support/deprecation'
71
+ require 'doorkeeper/orm/active_record'
55
72
 
56
73
  module Doorkeeper
57
- def self.configured?
58
- ActiveSupport::Deprecation.warn "Method `Doorkeeper#configured?` has been deprecated without replacement."
59
- @config.present?
60
- end
61
-
62
- def self.database_installed?
63
- ActiveSupport::Deprecation.warn "Method `Doorkeeper#database_installed?` has been deprecated without replacement."
64
- [AccessToken, AccessGrant, Application].all?(&:table_exists?)
65
- end
66
-
67
- def self.installed?
68
- ActiveSupport::Deprecation.warn "Method `Doorkeeper#installed?` has been deprecated without replacement."
69
- configured? && database_installed?
70
- end
71
-
72
74
  def self.authenticate(request, methods = Doorkeeper.configuration.access_token_methods)
73
75
  OAuth::Token.authenticate(request, *methods)
74
76
  end
@@ -1,27 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
1
4
  require 'rails/generators/active_record'
2
5
 
3
- class Doorkeeper::ApplicationOwnerGenerator < Rails::Generators::Base
4
- include Rails::Generators::Migration
5
- source_root File.expand_path('../templates', __FILE__)
6
- desc 'Provide support for client application ownership.'
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
- def application_owner
9
- migration_template(
10
- 'add_owner_to_application_migration.rb.erb',
11
- 'db/migrate/add_owner_to_application.rb',
12
- migration_version: migration_version
13
- )
14
- end
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
15
19
 
16
- def self.next_migration_number(dirname)
17
- ActiveRecord::Generators::Base.next_migration_number(dirname)
18
- end
20
+ def self.next_migration_number(dirname)
21
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
22
+ end
19
23
 
20
- private
24
+ private
21
25
 
22
- def migration_version
23
- if ActiveRecord::VERSION::MAJOR >= 5
24
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
26
+ def migration_version
27
+ if ActiveRecord::VERSION::MAJOR >= 5
28
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
29
+ end
25
30
  end
26
31
  end
27
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
- class Doorkeeper::InstallGenerator < ::Rails::Generators::Base
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
- def install
7
- template 'initializer.rb', 'config/initializers/doorkeeper.rb'
8
- copy_file File.expand_path('../../../../config/locales/en.yml', __FILE__), 'config/locales/doorkeeper.en.yml'
9
- route 'use_doorkeeper'
10
- readme 'README'
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,27 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
1
4
  require 'rails/generators/active_record'
2
5
 
3
- class Doorkeeper::MigrationGenerator < ::Rails::Generators::Base
4
- include Rails::Generators::Migration
5
- source_root File.expand_path('../templates', __FILE__)
6
- desc 'Installs Doorkeeper migration file.'
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
- def install
9
- migration_template(
10
- 'migration.rb.erb',
11
- 'db/migrate/create_doorkeeper_tables.rb',
12
- migration_version: migration_version
13
- )
14
- end
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
15
19
 
16
- def self.next_migration_number(dirname)
17
- ActiveRecord::Generators::Base.next_migration_number(dirname)
18
- end
20
+ def self.next_migration_number(dirname)
21
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
22
+ end
19
23
 
20
- private
24
+ private
21
25
 
22
- def migration_version
23
- if ActiveRecord::VERSION::MAJOR >= 5
24
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
26
+ def migration_version
27
+ if ActiveRecord::VERSION::MAJOR >= 5
28
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
29
+ end
25
30
  end
26
31
  end
27
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,35 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
1
4
  require 'rails/generators/active_record'
2
5
 
3
- class Doorkeeper::PreviousRefreshTokenGenerator < Rails::Generators::Base
4
- include Rails::Generators::Migration
5
- source_root File.expand_path('../templates', __FILE__)
6
- desc 'Support revoke refresh token on access token use'
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
- def self.next_migration_number(path)
9
- ActiveRecord::Generators::Base.next_migration_number(path)
10
- end
12
+ def self.next_migration_number(path)
13
+ ActiveRecord::Generators::Base.next_migration_number(path)
14
+ end
11
15
 
12
- def previous_refresh_token
13
- if no_previous_refresh_token_column?
14
- migration_template(
15
- 'add_previous_refresh_token_to_access_tokens.rb.erb',
16
- 'db/migrate/add_previous_refresh_token_to_access_tokens.rb'
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
- private
25
+ private
22
26
 
23
- def migration_version
24
- if ActiveRecord::VERSION::MAJOR >= 5
25
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
27
+ def migration_version
28
+ if ActiveRecord::VERSION::MAJOR >= 5
29
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
30
+ end
26
31
  end
27
- end
28
32
 
29
- def no_previous_refresh_token_column?
30
- !ActiveRecord::Base.connection.column_exists?(
31
- :oauth_access_tokens,
32
- :previous_refresh_token
33
- )
33
+ def no_previous_refresh_token_column?
34
+ !ActiveRecord::Base.connection.column_exists?(
35
+ :oauth_access_tokens,
36
+ :previous_refresh_token
37
+ )
38
+ end
34
39
  end
35
40
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddConfidentialToApplications < ActiveRecord::Migration<%= migration_version %>
4
+ def change
5
+ add_column(
6
+ :oauth_applications,
7
+ :confidential,
8
+ :boolean,
9
+ null: false,
10
+ default: true
11
+ )
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ class EnablePkce < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ add_column :oauth_access_grants, :code_challenge, :string, null: true
4
+ add_column :oauth_access_grants, :code_challenge_method, :string, null: true
5
+ end
6
+ end
@@ -4,56 +4,103 @@ 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
- fail "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"
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 want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
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
- # Admin.find_by_id(session[:admin_id]) || redirect_to(new_admin_session_url)
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 a custom TTL for implicit grants.
28
- # custom_access_token_expires_in do |oauth_client|
29
- # oauth_client.application.additional_settings.implicit_oauth_expiration
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
 
@@ -62,6 +109,7 @@ Doorkeeper.configure do
62
109
  # falls back to the `:client_id` and `:client_secret` params from the `params` object.
63
110
  # Check out https://github.com/doorkeeper-gem/doorkeeper/wiki/Changing-how-clients-are-authenticated
64
111
  # for more information on customization
112
+ #
65
113
  # client_credentials :from_basic, :from_params
66
114
 
67
115
  # Change the way access token is authenticated from the request object.
@@ -69,6 +117,7 @@ Doorkeeper.configure do
69
117
  # falls back to the `:access_token` or `:bearer_token` params from the `params` object.
70
118
  # Check out https://github.com/doorkeeper-gem/doorkeeper/wiki/Changing-how-clients-are-authenticated
71
119
  # for more information on customization
120
+ #
72
121
  # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
73
122
 
74
123
  # Change the native redirect uri for client apps
@@ -90,8 +139,8 @@ Doorkeeper.configure do
90
139
  #
91
140
  # force_ssl_in_redirect_uri { |uri| uri.host != 'localhost' }
92
141
 
93
- # Specify what redirect URI's you want to block during creation. Any redirect
94
- # URI is whitelisted by default.
142
+ # Specify what redirect URI's you want to block during Application creation.
143
+ # Any redirect URI is whitelisted by default.
95
144
  #
96
145
  # You can use this option in order to forbid URI's with 'javascript' scheme
97
146
  # for example.
@@ -127,13 +176,29 @@ Doorkeeper.configure do
127
176
  # puts "AFTER HOOK FIRED! #{request}, #{response}"
128
177
  # end
129
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
192
+
130
193
  # Under some circumstances you might want to have applications auto-approved,
131
194
  # so that the user skips the authorization step.
132
195
  # For example if dealing with a trusted application.
196
+ #
133
197
  # skip_authorization do |resource_owner, client|
134
198
  # client.superapp? or resource_owner.admin?
135
199
  # end
136
200
 
137
201
  # WWW-Authenticate Realm (default "Doorkeeper").
202
+ #
138
203
  # realm "Doorkeeper"
139
204
  end
@@ -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('../../../../app/views', __FILE__)
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