doorkeeper 5.3.2 → 5.5.0.rc1

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 (231) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +106 -2
  3. data/README.md +6 -4
  4. data/app/controllers/doorkeeper/applications_controller.rb +4 -4
  5. data/app/controllers/doorkeeper/authorizations_controller.rb +32 -12
  6. data/app/controllers/doorkeeper/authorized_applications_controller.rb +2 -2
  7. data/app/controllers/doorkeeper/tokens_controller.rb +60 -20
  8. data/app/views/doorkeeper/applications/_form.html.erb +1 -1
  9. data/app/views/doorkeeper/applications/show.html.erb +19 -2
  10. data/config/locales/en.yml +3 -2
  11. data/lib/doorkeeper.rb +107 -79
  12. data/lib/doorkeeper/config.rb +140 -94
  13. data/lib/doorkeeper/config/abstract_builder.rb +28 -0
  14. data/lib/doorkeeper/config/option.rb +26 -14
  15. data/lib/doorkeeper/config/validations.rb +53 -0
  16. data/lib/doorkeeper/engine.rb +1 -1
  17. data/lib/doorkeeper/grant_flow.rb +43 -0
  18. data/lib/doorkeeper/grant_flow/fallback_flow.rb +15 -0
  19. data/lib/doorkeeper/grant_flow/flow.rb +34 -0
  20. data/lib/doorkeeper/grant_flow/registry.rb +50 -0
  21. data/lib/doorkeeper/grape/helpers.rb +1 -1
  22. data/lib/doorkeeper/helpers/controller.rb +6 -4
  23. data/lib/doorkeeper/models/access_grant_mixin.rb +20 -16
  24. data/lib/doorkeeper/models/access_token_mixin.rb +110 -47
  25. data/lib/doorkeeper/models/application_mixin.rb +5 -4
  26. data/lib/doorkeeper/models/concerns/resource_ownerable.rb +47 -0
  27. data/lib/doorkeeper/models/concerns/revocable.rb +1 -1
  28. data/lib/doorkeeper/models/concerns/scopes.rb +5 -1
  29. data/lib/doorkeeper/models/concerns/secret_storable.rb +1 -3
  30. data/lib/doorkeeper/oauth/authorization/code.rb +15 -6
  31. data/lib/doorkeeper/oauth/authorization/context.rb +5 -5
  32. data/lib/doorkeeper/oauth/authorization/token.rb +14 -16
  33. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +4 -4
  34. data/lib/doorkeeper/oauth/authorization_code_request.rb +17 -14
  35. data/lib/doorkeeper/oauth/base_request.rb +12 -20
  36. data/lib/doorkeeper/oauth/client.rb +1 -1
  37. data/lib/doorkeeper/oauth/client/credentials.rb +2 -4
  38. data/lib/doorkeeper/oauth/client_credentials/creator.rb +27 -8
  39. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +4 -2
  40. data/lib/doorkeeper/oauth/client_credentials/validator.rb +4 -2
  41. data/lib/doorkeeper/oauth/client_credentials_request.rb +8 -7
  42. data/lib/doorkeeper/oauth/code_request.rb +3 -3
  43. data/lib/doorkeeper/oauth/code_response.rb +28 -14
  44. data/lib/doorkeeper/oauth/error_response.rb +6 -7
  45. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -8
  46. data/lib/doorkeeper/oauth/hooks/context.rb +21 -0
  47. data/lib/doorkeeper/oauth/invalid_token_response.rb +2 -2
  48. data/lib/doorkeeper/oauth/password_access_token_request.rb +24 -7
  49. data/lib/doorkeeper/oauth/pre_authorization.rb +41 -31
  50. data/lib/doorkeeper/oauth/refresh_token_request.rb +31 -22
  51. data/lib/doorkeeper/oauth/token.rb +5 -6
  52. data/lib/doorkeeper/oauth/token_introspection.rb +4 -8
  53. data/lib/doorkeeper/oauth/token_request.rb +3 -3
  54. data/lib/doorkeeper/oauth/token_response.rb +1 -1
  55. data/lib/doorkeeper/orm/active_record.rb +10 -2
  56. data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +8 -3
  57. data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +7 -3
  58. data/lib/doorkeeper/orm/active_record/mixins/application.rb +20 -16
  59. data/lib/doorkeeper/rails/routes.rb +14 -18
  60. data/lib/doorkeeper/rails/routes/abstract_router.rb +35 -0
  61. data/lib/doorkeeper/rails/routes/mapper.rb +2 -2
  62. data/lib/doorkeeper/rails/routes/registry.rb +45 -0
  63. data/lib/doorkeeper/request.rb +49 -12
  64. data/lib/doorkeeper/request/refresh_token.rb +2 -1
  65. data/lib/doorkeeper/request/strategy.rb +2 -2
  66. data/lib/doorkeeper/server.rb +4 -4
  67. data/lib/doorkeeper/stale_records_cleaner.rb +4 -4
  68. data/lib/doorkeeper/version.rb +3 -3
  69. data/lib/generators/doorkeeper/confidential_applications_generator.rb +1 -1
  70. data/lib/generators/doorkeeper/enable_polymorphic_resource_owner_generator.rb +39 -0
  71. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb +2 -0
  72. data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb.erb +2 -0
  73. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +2 -0
  74. data/lib/generators/doorkeeper/templates/enable_polymorphic_resource_owner_migration.rb.erb +17 -0
  75. data/lib/generators/doorkeeper/templates/initializer.rb +48 -10
  76. data/lib/generators/doorkeeper/templates/migration.rb.erb +14 -5
  77. metadata +21 -299
  78. data/Appraisals +0 -40
  79. data/CODE_OF_CONDUCT.md +0 -46
  80. data/CONTRIBUTING.md +0 -49
  81. data/Dangerfile +0 -67
  82. data/Dockerfile +0 -29
  83. data/Gemfile +0 -25
  84. data/NEWS.md +0 -1
  85. data/RELEASING.md +0 -11
  86. data/Rakefile +0 -28
  87. data/SECURITY.md +0 -15
  88. data/UPGRADE.md +0 -2
  89. data/bin/console +0 -16
  90. data/doorkeeper.gemspec +0 -42
  91. data/gemfiles/rails_5_0.gemfile +0 -18
  92. data/gemfiles/rails_5_1.gemfile +0 -18
  93. data/gemfiles/rails_5_2.gemfile +0 -18
  94. data/gemfiles/rails_6_0.gemfile +0 -18
  95. data/gemfiles/rails_master.gemfile +0 -18
  96. data/spec/controllers/application_metal_controller_spec.rb +0 -64
  97. data/spec/controllers/applications_controller_spec.rb +0 -274
  98. data/spec/controllers/authorizations_controller_spec.rb +0 -608
  99. data/spec/controllers/protected_resources_controller_spec.rb +0 -361
  100. data/spec/controllers/token_info_controller_spec.rb +0 -50
  101. data/spec/controllers/tokens_controller_spec.rb +0 -498
  102. data/spec/dummy/Rakefile +0 -9
  103. data/spec/dummy/app/assets/config/manifest.js +0 -2
  104. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  105. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -9
  106. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -14
  107. data/spec/dummy/app/controllers/home_controller.rb +0 -18
  108. data/spec/dummy/app/controllers/metal_controller.rb +0 -13
  109. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -13
  110. data/spec/dummy/app/helpers/application_helper.rb +0 -7
  111. data/spec/dummy/app/models/user.rb +0 -7
  112. data/spec/dummy/app/views/home/index.html.erb +0 -0
  113. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  114. data/spec/dummy/config.ru +0 -6
  115. data/spec/dummy/config/application.rb +0 -49
  116. data/spec/dummy/config/boot.rb +0 -7
  117. data/spec/dummy/config/database.yml +0 -15
  118. data/spec/dummy/config/environment.rb +0 -5
  119. data/spec/dummy/config/environments/development.rb +0 -31
  120. data/spec/dummy/config/environments/production.rb +0 -64
  121. data/spec/dummy/config/environments/test.rb +0 -45
  122. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -9
  123. data/spec/dummy/config/initializers/doorkeeper.rb +0 -166
  124. data/spec/dummy/config/initializers/secret_token.rb +0 -10
  125. data/spec/dummy/config/initializers/session_store.rb +0 -10
  126. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -16
  127. data/spec/dummy/config/locales/doorkeeper.en.yml +0 -5
  128. data/spec/dummy/config/routes.rb +0 -13
  129. data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -11
  130. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -7
  131. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -69
  132. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -9
  133. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -13
  134. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -8
  135. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -13
  136. data/spec/dummy/db/schema.rb +0 -68
  137. data/spec/dummy/public/404.html +0 -26
  138. data/spec/dummy/public/422.html +0 -26
  139. data/spec/dummy/public/500.html +0 -26
  140. data/spec/dummy/public/favicon.ico +0 -0
  141. data/spec/dummy/script/rails +0 -9
  142. data/spec/factories.rb +0 -30
  143. data/spec/generators/application_owner_generator_spec.rb +0 -28
  144. data/spec/generators/confidential_applications_generator_spec.rb +0 -29
  145. data/spec/generators/install_generator_spec.rb +0 -36
  146. data/spec/generators/migration_generator_spec.rb +0 -28
  147. data/spec/generators/pkce_generator_spec.rb +0 -28
  148. data/spec/generators/previous_refresh_token_generator_spec.rb +0 -44
  149. data/spec/generators/templates/routes.rb +0 -4
  150. data/spec/generators/views_generator_spec.rb +0 -29
  151. data/spec/grape/grape_integration_spec.rb +0 -137
  152. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +0 -26
  153. data/spec/lib/config_spec.rb +0 -809
  154. data/spec/lib/doorkeeper_spec.rb +0 -27
  155. data/spec/lib/models/expirable_spec.rb +0 -61
  156. data/spec/lib/models/reusable_spec.rb +0 -40
  157. data/spec/lib/models/revocable_spec.rb +0 -59
  158. data/spec/lib/models/scopes_spec.rb +0 -53
  159. data/spec/lib/models/secret_storable_spec.rb +0 -135
  160. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -39
  161. data/spec/lib/oauth/authorization_code_request_spec.rb +0 -170
  162. data/spec/lib/oauth/base_request_spec.rb +0 -224
  163. data/spec/lib/oauth/base_response_spec.rb +0 -45
  164. data/spec/lib/oauth/client/credentials_spec.rb +0 -90
  165. data/spec/lib/oauth/client_credentials/creator_spec.rb +0 -134
  166. data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -112
  167. data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -59
  168. data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -27
  169. data/spec/lib/oauth/client_credentials_request_spec.rb +0 -107
  170. data/spec/lib/oauth/client_spec.rb +0 -38
  171. data/spec/lib/oauth/code_request_spec.rb +0 -46
  172. data/spec/lib/oauth/code_response_spec.rb +0 -32
  173. data/spec/lib/oauth/error_response_spec.rb +0 -64
  174. data/spec/lib/oauth/error_spec.rb +0 -21
  175. data/spec/lib/oauth/forbidden_token_response_spec.rb +0 -20
  176. data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -110
  177. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -21
  178. data/spec/lib/oauth/helpers/uri_checker_spec.rb +0 -262
  179. data/spec/lib/oauth/invalid_request_response_spec.rb +0 -73
  180. data/spec/lib/oauth/invalid_token_response_spec.rb +0 -53
  181. data/spec/lib/oauth/password_access_token_request_spec.rb +0 -190
  182. data/spec/lib/oauth/pre_authorization_spec.rb +0 -223
  183. data/spec/lib/oauth/refresh_token_request_spec.rb +0 -177
  184. data/spec/lib/oauth/scopes_spec.rb +0 -146
  185. data/spec/lib/oauth/token_request_spec.rb +0 -157
  186. data/spec/lib/oauth/token_response_spec.rb +0 -84
  187. data/spec/lib/oauth/token_spec.rb +0 -156
  188. data/spec/lib/request/strategy_spec.rb +0 -54
  189. data/spec/lib/secret_storing/base_spec.rb +0 -60
  190. data/spec/lib/secret_storing/bcrypt_spec.rb +0 -49
  191. data/spec/lib/secret_storing/plain_spec.rb +0 -44
  192. data/spec/lib/secret_storing/sha256_hash_spec.rb +0 -48
  193. data/spec/lib/server_spec.rb +0 -49
  194. data/spec/lib/stale_records_cleaner_spec.rb +0 -89
  195. data/spec/models/doorkeeper/access_grant_spec.rb +0 -161
  196. data/spec/models/doorkeeper/access_token_spec.rb +0 -622
  197. data/spec/models/doorkeeper/application_spec.rb +0 -482
  198. data/spec/requests/applications/applications_request_spec.rb +0 -259
  199. data/spec/requests/applications/authorized_applications_spec.rb +0 -32
  200. data/spec/requests/endpoints/authorization_spec.rb +0 -91
  201. data/spec/requests/endpoints/token_spec.rb +0 -75
  202. data/spec/requests/flows/authorization_code_errors_spec.rb +0 -79
  203. data/spec/requests/flows/authorization_code_spec.rb +0 -525
  204. data/spec/requests/flows/client_credentials_spec.rb +0 -166
  205. data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -46
  206. data/spec/requests/flows/implicit_grant_spec.rb +0 -91
  207. data/spec/requests/flows/password_spec.rb +0 -316
  208. data/spec/requests/flows/refresh_token_spec.rb +0 -233
  209. data/spec/requests/flows/revoke_token_spec.rb +0 -157
  210. data/spec/requests/flows/skip_authorization_spec.rb +0 -66
  211. data/spec/requests/protected_resources/metal_spec.rb +0 -16
  212. data/spec/requests/protected_resources/private_api_spec.rb +0 -83
  213. data/spec/routing/custom_controller_routes_spec.rb +0 -133
  214. data/spec/routing/default_routes_spec.rb +0 -41
  215. data/spec/routing/scoped_routes_spec.rb +0 -47
  216. data/spec/spec_helper.rb +0 -54
  217. data/spec/spec_helper_integration.rb +0 -4
  218. data/spec/support/dependencies/factory_bot.rb +0 -4
  219. data/spec/support/doorkeeper_rspec.rb +0 -22
  220. data/spec/support/helpers/access_token_request_helper.rb +0 -13
  221. data/spec/support/helpers/authorization_request_helper.rb +0 -43
  222. data/spec/support/helpers/config_helper.rb +0 -11
  223. data/spec/support/helpers/model_helper.rb +0 -78
  224. data/spec/support/helpers/request_spec_helper.rb +0 -110
  225. data/spec/support/helpers/url_helper.rb +0 -62
  226. data/spec/support/orm/active_record.rb +0 -5
  227. data/spec/support/shared/controllers_shared_context.rb +0 -133
  228. data/spec/support/shared/hashing_shared_context.rb +0 -36
  229. data/spec/support/shared/models_shared_examples.rb +0 -54
  230. data/spec/validators/redirect_uri_validator_spec.rb +0 -183
  231. data/spec/version/version_spec.rb +0 -17
@@ -1,4 +1,4 @@
1
- <%= form_for application, url: doorkeeper_submit_path(application), html: { role: 'form' } do |f| %>
1
+ <%= form_for application, url: doorkeeper_submit_path(application), as: :doorkeeper_application, html: { role: 'form' } do |f| %>
2
2
  <% if application.errors.any? %>
3
3
  <div class="alert alert-danger" data-alert><p><%= t('doorkeeper.applications.form.error') %></p></div>
4
4
  <% end %>
@@ -8,10 +8,27 @@
8
8
  <p><code class="bg-light" id="application_id"><%= @application.uid %></code></p>
9
9
 
10
10
  <h4><%= t('.secret') %>:</h4>
11
- <p><code class="bg-light" id="secret"><%= flash[:application_secret].presence || @application.plaintext_secret %></code></p>
11
+ <p>
12
+ <code class="bg-light" id="secret">
13
+ <% secret = flash[:application_secret].presence || @application.plaintext_secret %>
14
+ <% if secret.blank? && Doorkeeper.config.application_secret_hashed? %>
15
+ <span class="bg-light font-italic text-uppercase text-muted"><%= t('.secret_hashed') %></span>
16
+ <% else %>
17
+ <%= secret %>
18
+ <% end %>
19
+ </code>
20
+ </p>
12
21
 
13
22
  <h4><%= t('.scopes') %>:</h4>
14
- <p><code class="bg-light" id="scopes"><%= @application.scopes.presence || raw('&nbsp;') %></code></p>
23
+ <p>
24
+ <code class="bg-light" id="scopes">
25
+ <% if @application.scopes.present? %>
26
+ <%= @application.scopes %>
27
+ <% else %>
28
+ <span class="bg-light font-italic text-uppercase text-muted"><%= t('.not_defined') %></span>
29
+ <% end %>
30
+ </code>
31
+ </p>
15
32
 
16
33
  <h4><%= t('.confidential') %>:</h4>
17
34
  <p><code class="bg-light" id="confidential"><%= @application.confidential? %></code></p>
@@ -51,12 +51,14 @@ en:
51
51
  title: 'New Application'
52
52
  show:
53
53
  title: 'Application: %{name}'
54
- application_id: 'Application UID'
54
+ application_id: 'UID'
55
55
  secret: 'Secret'
56
+ secret_hashed: 'Secret hashed'
56
57
  scopes: 'Scopes'
57
58
  confidential: 'Confidential'
58
59
  callback_urls: 'Callback urls'
59
60
  actions: 'Actions'
61
+ not_defined: 'Not defined'
60
62
 
61
63
  authorizations:
62
64
  buttons:
@@ -91,7 +93,6 @@ en:
91
93
  invalid_request:
92
94
  unknown: 'The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.'
93
95
  missing_param: 'Missing required parameter: %{value}.'
94
- not_support_pkce: 'Invalid code_verifier parameter. Server does not support pkce.'
95
96
  request_not_authorized: 'Request need to be authorized. Required parameter for authorizing request is missing or invalid.'
96
97
  invalid_redirect_uri: "The requested redirect uri is malformed or doesn't match client redirect URI."
97
98
  unauthorized_client: 'The client is not authorized to perform this request using this method.'
@@ -1,89 +1,117 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "doorkeeper/version"
4
- require "doorkeeper/engine"
5
3
  require "doorkeeper/config"
6
-
7
- require "doorkeeper/request/strategy"
8
- require "doorkeeper/request/authorization_code"
9
- require "doorkeeper/request/client_credentials"
10
- require "doorkeeper/request/code"
11
- require "doorkeeper/request/password"
12
- require "doorkeeper/request/refresh_token"
13
- require "doorkeeper/request/token"
14
-
15
- require "doorkeeper/errors"
16
- require "doorkeeper/server"
17
- require "doorkeeper/request"
18
- require "doorkeeper/validations"
19
-
20
- require "doorkeeper/oauth/authorization/code"
21
- require "doorkeeper/oauth/authorization/context"
22
- require "doorkeeper/oauth/authorization/token"
23
- require "doorkeeper/oauth/authorization/uri_builder"
24
- require "doorkeeper/oauth/helpers/scope_checker"
25
- require "doorkeeper/oauth/helpers/uri_checker"
26
- require "doorkeeper/oauth/helpers/unique_token"
27
-
28
- require "doorkeeper/oauth"
29
- require "doorkeeper/oauth/scopes"
30
- require "doorkeeper/oauth/error"
31
- require "doorkeeper/oauth/base_response"
32
- require "doorkeeper/oauth/code_response"
33
- require "doorkeeper/oauth/token_response"
34
- require "doorkeeper/oauth/error_response"
35
- require "doorkeeper/oauth/pre_authorization"
36
- require "doorkeeper/oauth/base_request"
37
- require "doorkeeper/oauth/authorization_code_request"
38
- require "doorkeeper/oauth/refresh_token_request"
39
- require "doorkeeper/oauth/password_access_token_request"
40
-
41
- require "doorkeeper/oauth/client_credentials/validator"
42
- require "doorkeeper/oauth/client_credentials/creator"
43
- require "doorkeeper/oauth/client_credentials/issuer"
44
- require "doorkeeper/oauth/client/credentials"
45
-
46
- require "doorkeeper/oauth/client_credentials_request"
47
- require "doorkeeper/oauth/code_request"
48
- require "doorkeeper/oauth/token_request"
49
- require "doorkeeper/oauth/client"
50
- require "doorkeeper/oauth/token"
51
- require "doorkeeper/oauth/token_introspection"
52
- require "doorkeeper/oauth/invalid_token_response"
53
- require "doorkeeper/oauth/forbidden_token_response"
54
- require "doorkeeper/oauth/invalid_request_response"
55
- require "doorkeeper/oauth/nonstandard"
56
-
57
- require "doorkeeper/secret_storing/base"
58
- require "doorkeeper/secret_storing/plain"
59
- require "doorkeeper/secret_storing/sha256_hash"
60
- require "doorkeeper/secret_storing/bcrypt"
61
-
62
- require "doorkeeper/models/concerns/orderable"
63
- require "doorkeeper/models/concerns/scopes"
64
- require "doorkeeper/models/concerns/expirable"
65
- require "doorkeeper/models/concerns/reusable"
66
- require "doorkeeper/models/concerns/revocable"
67
- require "doorkeeper/models/concerns/accessible"
68
- require "doorkeeper/models/concerns/secret_storable"
69
-
70
- require "doorkeeper/models/access_grant_mixin"
71
- require "doorkeeper/models/access_token_mixin"
72
- require "doorkeeper/models/application_mixin"
73
-
74
- require "doorkeeper/helpers/controller"
75
-
76
- require "doorkeeper/rails/routes"
77
- require "doorkeeper/rails/helpers"
78
-
79
- require "doorkeeper/rake"
80
- require "doorkeeper/stale_records_cleaner"
81
-
82
- require "doorkeeper/orm/active_record"
4
+ require "doorkeeper/engine"
83
5
 
84
6
  # Main Doorkeeper namespace.
85
7
  #
86
8
  module Doorkeeper
9
+ autoload :Errors, "doorkeeper/errors"
10
+ autoload :GrantFlow, "doorkeeper/grant_flow"
11
+ autoload :OAuth, "doorkeeper/oauth"
12
+ autoload :Rake, "doorkeeper/rake"
13
+ autoload :Request, "doorkeeper/request"
14
+ autoload :Server, "doorkeeper/server"
15
+ autoload :StaleRecordsCleaner, "doorkeeper/stale_records_cleaner"
16
+ autoload :Validations, "doorkeeper/validations"
17
+ autoload :VERSION, "doorkeeper/version"
18
+
19
+ autoload :AccessGrantMixin, "doorkeeper/models/access_grant_mixin"
20
+ autoload :AccessTokenMixin, "doorkeeper/models/access_token_mixin"
21
+ autoload :ApplicationMixin, "doorkeeper/models/application_mixin"
22
+
23
+ module Helpers
24
+ autoload :Controller, "doorkeeper/helpers/controller"
25
+ end
26
+
27
+ module Request
28
+ autoload :Strategy, "doorkeeper/request/strategy"
29
+ autoload :AuthorizationCode, "doorkeeper/request/authorization_code"
30
+ autoload :ClientCredentials, "doorkeeper/request/client_credentials"
31
+ autoload :Code, "doorkeeper/request/code"
32
+ autoload :Password, "doorkeeper/request/password"
33
+ autoload :RefreshToken, "doorkeeper/request/refresh_token"
34
+ autoload :Token, "doorkeeper/request/token"
35
+ end
36
+
37
+ module OAuth
38
+ autoload :BaseRequest, "doorkeeper/oauth/base_request"
39
+ autoload :AuthorizationCodeRequest, "doorkeeper/oauth/authorization_code_request"
40
+ autoload :BaseResponse, "doorkeeper/oauth/base_response"
41
+ autoload :CodeResponse, "doorkeeper/oauth/code_response"
42
+ autoload :Client, "doorkeeper/oauth/client"
43
+ autoload :ClientCredentialsRequest, "doorkeeper/oauth/client_credentials_request"
44
+ autoload :CodeRequest, "doorkeeper/oauth/code_request"
45
+ autoload :ErrorResponse, "doorkeeper/oauth/error_response"
46
+ autoload :Error, "doorkeeper/oauth/error"
47
+ autoload :InvalidTokenResponse, "doorkeeper/oauth/invalid_token_response"
48
+ autoload :InvalidRequestResponse, "doorkeeper/oauth/invalid_request_response"
49
+ autoload :ForbiddenTokenResponse, "doorkeeper/oauth/forbidden_token_response"
50
+ autoload :NonStandard, "doorkeeper/oauth/nonstandard"
51
+ autoload :PasswordAccessTokenRequest, "doorkeeper/oauth/password_access_token_request"
52
+ autoload :PreAuthorization, "doorkeeper/oauth/pre_authorization"
53
+ autoload :RefreshTokenRequest, "doorkeeper/oauth/refresh_token_request"
54
+ autoload :Scopes, "doorkeeper/oauth/scopes"
55
+ autoload :Token, "doorkeeper/oauth/token"
56
+ autoload :TokenIntrospection, "doorkeeper/oauth/token_introspection"
57
+ autoload :TokenRequest, "doorkeeper/oauth/token_request"
58
+ autoload :TokenResponse, "doorkeeper/oauth/token_response"
59
+
60
+ module Authorization
61
+ autoload :Code, "doorkeeper/oauth/authorization/code"
62
+ autoload :Context, "doorkeeper/oauth/authorization/context"
63
+ autoload :Token, "doorkeeper/oauth/authorization/token"
64
+ autoload :URIBuilder, "doorkeeper/oauth/authorization/uri_builder"
65
+ end
66
+
67
+ class Client
68
+ autoload :Credentials, "doorkeeper/oauth/client/credentials"
69
+ end
70
+
71
+ module ClientCredentials
72
+ autoload :Validator, "doorkeeper/oauth/client_credentials/validator"
73
+ autoload :Creator, "doorkeeper/oauth/client_credentials/creator"
74
+ autoload :Issuer, "doorkeeper/oauth/client_credentials/issuer"
75
+ end
76
+
77
+ module Helpers
78
+ autoload :ScopeChecker, "doorkeeper/oauth/helpers/scope_checker"
79
+ autoload :URIChecker, "doorkeeper/oauth/helpers/uri_checker"
80
+ autoload :UniqueToken, "doorkeeper/oauth/helpers/unique_token"
81
+ end
82
+
83
+ module Hooks
84
+ autoload :Context, "doorkeeper/oauth/hooks/context"
85
+ end
86
+ end
87
+
88
+ module Models
89
+ autoload :Accessible, "doorkeeper/models/concerns/accessible"
90
+ autoload :Expirable, "doorkeeper/models/concerns/expirable"
91
+ autoload :Orderable, "doorkeeper/models/concerns/orderable"
92
+ autoload :Scopes, "doorkeeper/models/concerns/scopes"
93
+ autoload :Reusable, "doorkeeper/models/concerns/reusable"
94
+ autoload :ResourceOwnerable, "doorkeeper/models/concerns/resource_ownerable"
95
+ autoload :Revocable, "doorkeeper/models/concerns/revocable"
96
+ autoload :SecretStorable, "doorkeeper/models/concerns/secret_storable"
97
+ end
98
+
99
+ module Orm
100
+ autoload :ActiveRecord, "doorkeeper/orm/active_record"
101
+ end
102
+
103
+ module Rails
104
+ autoload :Helpers, "doorkeeper/rails/helpers"
105
+ autoload :Routes, "doorkeeper/rails/routes"
106
+ end
107
+
108
+ module SecretStoring
109
+ autoload :Base, "doorkeeper/secret_storing/base"
110
+ autoload :Plain, "doorkeeper/secret_storing/plain"
111
+ autoload :Sha256Hash, "doorkeeper/secret_storing/sha256_hash"
112
+ autoload :BCrypt, "doorkeeper/secret_storing/bcrypt"
113
+ end
114
+
87
115
  def self.authenticate(request, methods = Doorkeeper.config.access_token_methods)
88
116
  OAuth::Token.authenticate(request, *methods)
89
117
  end
@@ -1,16 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "doorkeeper/config/abstract_builder"
3
4
  require "doorkeeper/config/option"
5
+ require "doorkeeper/config/validations"
4
6
 
5
7
  module Doorkeeper
8
+ # Defines a MissingConfiguration error for a missing Doorkeeper configuration
9
+ #
6
10
  class MissingConfiguration < StandardError
7
- # Defines a MissingConfiguration error for a missing Doorkeeper
8
- # configuration
9
11
  def initialize
10
12
  super("Configuration for doorkeeper missing. Do you have doorkeeper initializer?")
11
13
  end
12
14
  end
13
15
 
16
+ # Doorkeeper option DSL could be reused in extensions to build their own
17
+ # configurations. To use the Option DSL gems need to define `builder_class` method
18
+ # that returns configuration Builder class. This exception raises when they don't
19
+ # define it.
20
+ #
21
+ class MissingConfigurationBuilderClass < StandardError; end
22
+
14
23
  class << self
15
24
  def configure(&block)
16
25
  @config = Config::Builder.new(&block).build
@@ -30,7 +39,7 @@ module Doorkeeper
30
39
  @orm_adapter = "doorkeeper/orm/#{configuration.orm}".classify.constantize
31
40
  rescue NameError => e
32
41
  raise e, "ORM adapter not found (#{configuration.orm})", <<-ERROR_MSG.strip_heredoc
33
- [doorkeeper] ORM adapter not found (#{configuration.orm}), or there was an error
42
+ [DOORKEEPER] ORM adapter not found (#{configuration.orm}), or there was an error
34
43
  trying to load it.
35
44
 
36
45
  You probably need to add the related gem for this adapter to work with
@@ -48,17 +57,8 @@ module Doorkeeper
48
57
  end
49
58
 
50
59
  class Config
51
- class Builder
52
- def initialize(&block)
53
- @config = Config.new
54
- instance_eval(&block)
55
- end
56
-
57
- def build
58
- @config.validate
59
- @config
60
- end
61
-
60
+ # Default Doorkeeper configuration builder
61
+ class Builder < AbstractBuilder
62
62
  # Provide support for an owner to be assigned to each registered
63
63
  # application (disabled by default)
64
64
  # Optional parameter confirmation: true (default false) if you want
@@ -135,15 +135,6 @@ module Doorkeeper
135
135
  @config.instance_variable_set(:@reuse_access_token, true)
136
136
  end
137
137
 
138
- # Sets the token_reuse_limit
139
- # It will be used only when reuse_access_token option in enabled
140
- # By default it will be 100
141
- # It will be used for token reusablity to some threshold percentage
142
- # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/1189
143
- def token_reuse_limit(percentage)
144
- @config.instance_variable_set(:@token_reuse_limit, percentage)
145
- end
146
-
147
138
  # TODO: maybe make it more generic for other flows too?
148
139
  # Only allow one valid access token obtained via client credentials
149
140
  # per client. If a new access token is obtained before the old one
@@ -158,6 +149,12 @@ module Doorkeeper
158
149
  @config.instance_variable_set(:@api_only, true)
159
150
  end
160
151
 
152
+ # Enables polymorphic Resource Owner association for Access Grant and
153
+ # Access Token models. Requires additional database columns to be setup.
154
+ def use_polymorphic_resource_owner
155
+ @config.instance_variable_set(:@polymorphic_resource_owner, true)
156
+ end
157
+
161
158
  # Forbids creating/updating applications with arbitrary scopes that are
162
159
  # not in configuration, i.e. `default_scopes` or `optional_scopes`.
163
160
  # (disabled by default)
@@ -219,7 +216,11 @@ module Doorkeeper
219
216
  end
220
217
  end
221
218
 
219
+ # Replace with `default: Builder` when we drop support of Rails < 5.2
220
+ mattr_reader(:builder_class) { Builder }
221
+
222
222
  extend Option
223
+ include Validations
223
224
 
224
225
  option :resource_owner_authenticator,
225
226
  as: :authenticate_resource_owner,
@@ -251,8 +252,8 @@ module Doorkeeper
251
252
  end)
252
253
 
253
254
  # Hooks for authorization
254
- option :before_successful_authorization, default: ->(_context) {}
255
- option :after_successful_authorization, default: ->(_context) {}
255
+ option :before_successful_authorization, default: ->(_controller, _context = nil) {}
256
+ option :after_successful_authorization, default: ->(_controller, _context = nil) {}
256
257
  # Hooks for strategies responses
257
258
  option :before_successful_strategy_response, default: ->(_request) {}
258
259
  option :after_successful_strategy_response, default: ->(_request, _response) {}
@@ -265,10 +266,28 @@ module Doorkeeper
265
266
  option :authorization_code_expires_in, default: 600
266
267
  option :orm, default: :active_record
267
268
  option :native_redirect_uri, default: "urn:ietf:wg:oauth:2.0:oob", deprecated: true
268
- option :active_record_options, default: {}
269
269
  option :grant_flows, default: %w[authorization_code client_credentials]
270
270
  option :handle_auth_errors, default: :render
271
271
  option :token_lookup_batch_size, default: 10_000
272
+ # Sets the token_reuse_limit
273
+ # It will be used only when reuse_access_token option in enabled
274
+ # By default it will be 100
275
+ # It will be used for token reusablity to some threshold percentage
276
+ # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/1189
277
+ option :token_reuse_limit, default: 100
278
+
279
+ # [NOTE]: will be removed in a future version of Doorkeeper
280
+ option :skip_client_authentication_for_password_grant,
281
+ default: false,
282
+ deprecated: { message: "OAuth RFC requires client authentication so you need at least to create one" }
283
+
284
+ option :active_record_options,
285
+ default: {},
286
+ deprecated: { message: "Customize Doorkeeper models instead" }
287
+
288
+ # Hook to allow arbitrary user-client authorization
289
+ option :authorize_resource_owner_for_client,
290
+ default: ->(_client, _resource_owner) { true }
272
291
 
273
292
  # Allows to customize OAuth grant flows that +each+ application support.
274
293
  # You can configure a custom block (or use a class respond to `#call`) that must
@@ -410,21 +429,26 @@ module Doorkeeper
410
429
  :token_secret_fallback_strategy,
411
430
  :application_secret_fallback_strategy
412
431
 
413
- # Return the valid subset of this configuration
414
- def validate
415
- validate_reuse_access_token_value
416
- validate_token_reuse_limit
417
- validate_secret_strategies
418
- end
419
-
432
+ # Doorkeeper Access Token model class.
433
+ #
434
+ # @return [ActiveRecord::Base, Mongoid::Document, Sequel::Model]
435
+ #
420
436
  def access_token_model
421
437
  @access_token_model ||= access_token_class.constantize
422
438
  end
423
439
 
440
+ # Doorkeeper Access Grant model class.
441
+ #
442
+ # @return [ActiveRecord::Base, Mongoid::Document, Sequel::Model]
443
+ #
424
444
  def access_grant_model
425
445
  @access_grant_model ||= access_grant_class.constantize
426
446
  end
427
447
 
448
+ # Doorkeeper Application model class.
449
+ #
450
+ # @return [ActiveRecord::Base, Mongoid::Document, Sequel::Model]
451
+ #
428
452
  def application_model
429
453
  @application_model ||= application_class.constantize
430
454
  end
@@ -445,14 +469,6 @@ module Doorkeeper
445
469
  end
446
470
  end
447
471
 
448
- def token_reuse_limit
449
- @token_reuse_limit ||= 100
450
- end
451
-
452
- def revoke_previous_client_credentials_token
453
- @revoke_previous_client_credentials_token || false
454
- end
455
-
456
472
  def resolve_controller(name)
457
473
  config_option = public_send(:"#{name}_controller")
458
474
  controller_name = if config_option.respond_to?(:call)
@@ -464,6 +480,10 @@ module Doorkeeper
464
480
  controller_name.constantize
465
481
  end
466
482
 
483
+ def revoke_previous_client_credentials_token?
484
+ option_set? :revoke_previous_client_credentials_token
485
+ end
486
+
467
487
  def enforce_configured_scopes?
468
488
  option_set? :enforce_configured_scopes
469
489
  end
@@ -472,6 +492,10 @@ module Doorkeeper
472
492
  option_set? :enable_application_owner
473
493
  end
474
494
 
495
+ def polymorphic_resource_owner?
496
+ option_set? :polymorphic_resource_owner
497
+ end
498
+
475
499
  def confirm_application_owner?
476
500
  option_set? :confirm_application_owner
477
501
  end
@@ -480,6 +504,10 @@ module Doorkeeper
480
504
  handle_auth_errors == :raise
481
505
  end
482
506
 
507
+ def application_secret_hashed?
508
+ instance_variable_defined?(:"@application_secret_strategy")
509
+ end
510
+
483
511
  def token_secret_strategy
484
512
  @token_secret_strategy ||= ::Doorkeeper::SecretStoring::Plain
485
513
  end
@@ -516,12 +544,77 @@ module Doorkeeper
516
544
  ]
517
545
  end
518
546
 
547
+ def enabled_grant_flows
548
+ @enabled_grant_flows ||= calculate_grant_flows.map { |name| Doorkeeper::GrantFlow.get(name) }.compact
549
+ end
550
+
551
+ def authorization_response_flows
552
+ @authorization_response_flows ||= enabled_grant_flows.select(&:handles_response_type?) +
553
+ deprecated_authorization_flows
554
+ end
555
+
556
+ def token_grant_flows
557
+ @token_grant_flows ||= calculate_token_grant_flows
558
+ end
559
+
519
560
  def authorization_response_types
520
- @authorization_response_types ||= calculate_authorization_response_types.freeze
561
+ authorization_response_flows.map(&:response_type_matches)
521
562
  end
522
563
 
523
564
  def token_grant_types
524
- @token_grant_types ||= calculate_token_grant_types.freeze
565
+ token_grant_flows.map(&:grant_type_matches)
566
+ end
567
+
568
+ # [NOTE]: deprecated and will be removed soon
569
+ def deprecated_token_grant_types_resolver
570
+ @deprecated_token_grant_types ||= calculate_token_grant_types
571
+ end
572
+
573
+ # [NOTE]: deprecated and will be removed soon
574
+ def deprecated_authorization_flows
575
+ response_types = calculate_authorization_response_types
576
+
577
+ if response_types.any?
578
+ ::Kernel.warn <<~WARNING
579
+ Please, don't patch Doorkeeper::Config#calculate_authorization_response_types method.
580
+ Register your custom grant flows using the public API:
581
+ `Doorkeeper::GrantFlow.register(grant_flow_name, **options)`.
582
+ WARNING
583
+ end
584
+
585
+ response_types.map do |response_type|
586
+ Doorkeeper::GrantFlow::FallbackFlow.new(response_type, response_type_matches: response_type)
587
+ end
588
+ end
589
+
590
+ # [NOTE]: deprecated and will be removed soon
591
+ def calculate_authorization_response_types
592
+ []
593
+ end
594
+
595
+ # [NOTE]: deprecated and will be removed soon
596
+ def calculate_token_grant_types
597
+ types = grant_flows - ["implicit"]
598
+ types << "refresh_token" if refresh_token_enabled?
599
+ types
600
+ end
601
+
602
+ # Calculates grant flows configured by the user in Doorkeeper
603
+ # configuration considering registered aliases that is exposed
604
+ # to single or multiple other flows.
605
+ #
606
+ def calculate_grant_flows
607
+ configured_flows = grant_flows.map(&:to_s)
608
+ aliases = Doorkeeper::GrantFlow.aliases.keys.map(&:to_s)
609
+
610
+ flows = configured_flows - aliases
611
+ aliases.each do |flow_alias|
612
+ next unless configured_flows.include?(flow_alias)
613
+
614
+ flows.concat(Doorkeeper::GrantFlow.expand_alias(flow_alias))
615
+ end
616
+
617
+ flows.flatten.uniq
525
618
  end
526
619
 
527
620
  def allow_blank_redirect_uri?(application = nil)
@@ -550,57 +643,10 @@ module Doorkeeper
550
643
  !!(defined?(var) && var)
551
644
  end
552
645
 
553
- # Determines what values are acceptable for 'response_type' param in
554
- # authorization request endpoint, and return them as an array of strings.
555
- #
556
- def calculate_authorization_response_types
557
- types = []
558
- types << "code" if grant_flows.include? "authorization_code"
559
- types << "token" if grant_flows.include? "implicit"
560
- types
561
- end
562
-
563
- # Determines what values are acceptable for 'grant_type' param token
564
- # request endpoint, and return them in array.
565
- #
566
- def calculate_token_grant_types
567
- types = grant_flows - ["implicit"]
568
- types << "refresh_token" if refresh_token_enabled?
569
- types
570
- end
571
-
572
- # Determine whether +reuse_access_token+ and a non-restorable
573
- # +token_secret_strategy+ have both been activated.
574
- #
575
- # In that case, disable reuse_access_token value and warn the user.
576
- def validate_reuse_access_token_value
577
- strategy = token_secret_strategy
578
- return if !reuse_access_token || strategy.allows_restoring_secrets?
579
-
580
- ::Rails.logger.warn(
581
- "You have configured both reuse_access_token " \
582
- "AND strategy strategy '#{strategy}' that cannot restore tokens. " \
583
- "This combination is unsupported. reuse_access_token will be disabled",
584
- )
585
- @reuse_access_token = false
586
- end
587
-
588
- # Validate that the provided strategies are valid for
589
- # tokens and applications
590
- def validate_secret_strategies
591
- token_secret_strategy.validate_for :token
592
- application_secret_strategy.validate_for :application
593
- end
594
-
595
- def validate_token_reuse_limit
596
- return if !reuse_access_token ||
597
- (token_reuse_limit > 0 && token_reuse_limit <= 100)
598
-
599
- ::Rails.logger.warn(
600
- "You have configured an invalid value for token_reuse_limit option. " \
601
- "It will be set to default 100",
602
- )
603
- @token_reuse_limit = 100
646
+ def calculate_token_grant_flows
647
+ flows = enabled_grant_flows.select(&:handles_grant_type?)
648
+ flows << Doorkeeper::GrantFlow.get("refresh_token") if refresh_token_enabled?
649
+ flows
604
650
  end
605
651
  end
606
652
  end