doorkeeper 5.5.4 → 5.8.1

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -8
  3. data/README.md +5 -9
  4. data/app/controllers/doorkeeper/authorizations_controller.rb +34 -11
  5. data/app/controllers/doorkeeper/tokens_controller.rb +28 -6
  6. data/app/views/doorkeeper/authorizations/error.html.erb +3 -1
  7. data/app/views/doorkeeper/authorizations/form_post.html.erb +1 -1
  8. data/app/views/doorkeeper/authorizations/new.html.erb +16 -16
  9. data/config/locales/en.yml +4 -1
  10. data/lib/doorkeeper/config/abstract_builder.rb +1 -1
  11. data/lib/doorkeeper/config/validations.rb +15 -3
  12. data/lib/doorkeeper/config.rb +95 -55
  13. data/lib/doorkeeper/engine.rb +10 -3
  14. data/lib/doorkeeper/errors.rb +32 -0
  15. data/lib/doorkeeper/helpers/controller.rb +1 -1
  16. data/lib/doorkeeper/models/access_token_mixin.rb +71 -9
  17. data/lib/doorkeeper/models/concerns/expiration_time_sql_math.rb +88 -0
  18. data/lib/doorkeeper/models/concerns/polymorphic_resource_owner.rb +30 -0
  19. data/lib/doorkeeper/oauth/authorization/code.rb +7 -1
  20. data/lib/doorkeeper/oauth/authorization/token.rb +7 -1
  21. data/lib/doorkeeper/oauth/authorization_code_request.rb +36 -12
  22. data/lib/doorkeeper/oauth/base_request.rb +14 -12
  23. data/lib/doorkeeper/oauth/client.rb +1 -1
  24. data/lib/doorkeeper/oauth/client_credentials/creator.rb +13 -13
  25. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +5 -4
  26. data/lib/doorkeeper/oauth/client_credentials/validator.rb +4 -5
  27. data/lib/doorkeeper/oauth/client_credentials_request.rb +10 -2
  28. data/lib/doorkeeper/oauth/code_request.rb +1 -1
  29. data/lib/doorkeeper/oauth/error.rb +4 -3
  30. data/lib/doorkeeper/oauth/error_response.rb +19 -4
  31. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +4 -4
  32. data/lib/doorkeeper/oauth/invalid_request_response.rb +4 -0
  33. data/lib/doorkeeper/oauth/password_access_token_request.rb +6 -6
  34. data/lib/doorkeeper/oauth/pre_authorization.rb +31 -23
  35. data/lib/doorkeeper/oauth/refresh_token_request.rb +17 -9
  36. data/lib/doorkeeper/oauth/scopes.rb +55 -1
  37. data/lib/doorkeeper/oauth/token_introspection.rb +34 -20
  38. data/lib/doorkeeper/oauth/token_request.rb +1 -1
  39. data/lib/doorkeeper/oauth/token_response.rb +5 -3
  40. data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +0 -6
  41. data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +21 -4
  42. data/lib/doorkeeper/orm/active_record/mixins/application.rb +22 -4
  43. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +2 -2
  44. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +5 -2
  45. data/lib/doorkeeper/orm/active_record.rb +30 -37
  46. data/lib/doorkeeper/rails/routes.rb +12 -3
  47. data/lib/doorkeeper/rake/setup.rake +0 -5
  48. data/lib/doorkeeper/revocable_tokens/revocable_access_token.rb +21 -0
  49. data/lib/doorkeeper/revocable_tokens/revocable_refresh_token.rb +21 -0
  50. data/lib/doorkeeper/version.rb +2 -2
  51. data/lib/doorkeeper.rb +78 -5
  52. data/lib/generators/doorkeeper/remove_applications_secret_not_null_constraint_generator.rb +33 -0
  53. data/lib/generators/doorkeeper/templates/initializer.rb +44 -6
  54. data/lib/generators/doorkeeper/templates/migration.rb.erb +15 -4
  55. data/lib/generators/doorkeeper/templates/remove_applications_secret_not_null_constraint.rb.erb +7 -0
  56. metadata +28 -21
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require "rails/generators/active_record"
5
+
6
+ module Doorkeeper
7
+ # Generates migration with which drops NOT NULL constraint and allows not
8
+ # to bloat the database with redundant secret value.
9
+ #
10
+ class RemoveApplicationSecretNotNullConstraint < ::Rails::Generators::Base
11
+ include ::Rails::Generators::Migration
12
+ source_root File.expand_path("templates", __dir__)
13
+ desc "Removes NOT NULL constraint for OAuth2 applications."
14
+
15
+ def enable_polymorphic_resource_owner
16
+ migration_template(
17
+ "remove_applications_secret_not_null_constraint.rb.erb",
18
+ "db/migrate/remove_applications_secret_not_null_constraint.rb",
19
+ migration_version: migration_version,
20
+ )
21
+ end
22
+
23
+ def self.next_migration_number(dirname)
24
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
25
+ end
26
+
27
+ private
28
+
29
+ def migration_version
30
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
31
+ end
32
+ end
33
+ end
@@ -32,7 +32,7 @@ Doorkeeper.configure do
32
32
  # You can use your own model classes if you need to extend (or even override) default
33
33
  # Doorkeeper models such as `Application`, `AccessToken` and `AccessGrant.
34
34
  #
35
- # Be default Doorkeeper ActiveRecord ORM uses it's own classes:
35
+ # By default Doorkeeper ActiveRecord ORM uses its own classes:
36
36
  #
37
37
  # access_token_class "Doorkeeper::AccessToken"
38
38
  # access_grant_class "Doorkeeper::AccessGrant"
@@ -91,7 +91,10 @@ Doorkeeper.configure do
91
91
  # authorization_code_expires_in 10.minutes
92
92
 
93
93
  # Access token expiration time (default: 2 hours).
94
- # If you want to disable expiration, set this to `nil`.
94
+ # If you set this to `nil` Doorkeeper will not expire the token and omit expires_in in response.
95
+ # It is RECOMMENDED to set expiration time explicitly.
96
+ # Prefer access_token_expires_in 100.years or similar,
97
+ # which would be functionally equivalent and avoid the risk of unexpected behavior by callers.
95
98
  #
96
99
  # access_token_expires_in 2.hours
97
100
 
@@ -126,9 +129,10 @@ Doorkeeper.configure do
126
129
 
127
130
  # Reuse access token for the same resource owner within an application (disabled by default).
128
131
  #
129
- # This option protects your application from creating new tokens before old valid one becomes
130
- # expired so your database doesn't bloat. Keep in mind that when this option is `on` Doorkeeper
131
- # doesn't updates existing token expiration time, it will create a new token instead.
132
+ # This option protects your application from creating new tokens before old **valid** one becomes
133
+ # expired so your database doesn't bloat. Keep in mind that when this option is enabled Doorkeeper
134
+ # doesn't update existing token expiration time, it will create a new token instead if no active matching
135
+ # token found for the application, resources owner and/or set of scopes.
132
136
  # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
133
137
  #
134
138
  # You can not enable this option together with +hash_token_secrets+.
@@ -163,6 +167,17 @@ Doorkeeper.configure do
163
167
  #
164
168
  # revoke_previous_client_credentials_token
165
169
 
170
+ # Only allow one valid access token obtained via authorization code
171
+ # per client. If a new access token is obtained before the old one
172
+ # expired, the old one gets revoked (disabled by default)
173
+ #
174
+ # revoke_previous_authorization_code_token
175
+
176
+ # Require non-confidential clients to use PKCE when using an authorization code
177
+ # to obtain an access_token (disabled by default)
178
+ #
179
+ # force_pkce
180
+
166
181
  # Hash access and refresh tokens before persisting them.
167
182
  # This will disable the possibility to use +reuse_access_token+
168
183
  # since plain values can no longer be retrieved.
@@ -311,6 +326,12 @@ Doorkeeper.configure do
311
326
  # Doorkeeper::Errors::TokenRevoked, Doorkeeper::Errors::TokenUnknown
312
327
  #
313
328
  # handle_auth_errors :raise
329
+ #
330
+ # If you want to redirect back to the client application in accordance with
331
+ # https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1, you can set
332
+ # +handle_auth_errors+ to :redirect
333
+ #
334
+ # handle_auth_errors :redirect
314
335
 
315
336
  # Customize token introspection response.
316
337
  # Allows to add your own fields to default one that are required by the OAuth spec
@@ -384,12 +405,29 @@ Doorkeeper.configure do
384
405
  # true in case resource owner authorized for the specific application or false in other
385
406
  # cases.
386
407
  #
387
- # Be default all Resource Owners are authorized to any Client (application).
408
+ # By default all Resource Owners are authorized to any Client (application).
388
409
  #
389
410
  # authorize_resource_owner_for_client do |client, resource_owner|
390
411
  # resource_owner.admin? || client.owners_allowlist.include?(resource_owner)
391
412
  # end
392
413
 
414
+ # Allows additional data fields to be sent while granting access to an application,
415
+ # and for this additional data to be included in subsequently generated access tokens.
416
+ # The 'authorizations/new' page will need to be overridden to include this additional data
417
+ # in the request params when granting access. The access grant and access token models
418
+ # will both need to respond to these additional data fields, and have a database column
419
+ # to store them in.
420
+ #
421
+ # Example:
422
+ # You have a multi-tenanted platform and want to be able to grant access to a specific
423
+ # tenant, rather than all the tenants a user has access to. You can use this config
424
+ # option to specify that a ':tenant_id' will be passed when authorizing. This tenant_id
425
+ # will be included in the access tokens. When a request is made with one of these access
426
+ # tokens, you can check that the requested data belongs to the specified tenant.
427
+ #
428
+ # Default value is an empty Array: []
429
+ # custom_access_token_attributes [:tenant_id]
430
+
393
431
  # Hook into the strategies' request & response life-cycle in case your
394
432
  # application needs advanced customization or logging:
395
433
  #
@@ -5,6 +5,7 @@ class CreateDoorkeeperTables < ActiveRecord::Migration<%= migration_version %>
5
5
  create_table :oauth_applications do |t|
6
6
  t.string :name, null: false
7
7
  t.string :uid, null: false
8
+ # Remove `null: false` or use conditional constraint if you are planning to use public clients.
8
9
  t.string :secret, null: false
9
10
 
10
11
  # Remove `null: false` if you are planning to use grant flows
@@ -24,9 +25,9 @@ class CreateDoorkeeperTables < ActiveRecord::Migration<%= migration_version %>
24
25
  t.string :token, null: false
25
26
  t.integer :expires_in, null: false
26
27
  t.text :redirect_uri, null: false
28
+ t.string :scopes, null: false, default: ''
27
29
  t.datetime :created_at, null: false
28
30
  t.datetime :revoked_at
29
- t.string :scopes, null: false, default: ''
30
31
  end
31
32
 
32
33
  add_index :oauth_access_grants, :token, unique: true
@@ -53,9 +54,9 @@ class CreateDoorkeeperTables < ActiveRecord::Migration<%= migration_version %>
53
54
 
54
55
  t.string :refresh_token
55
56
  t.integer :expires_in
56
- t.datetime :revoked_at
57
- t.datetime :created_at, null: false
58
57
  t.string :scopes
58
+ t.datetime :created_at, null: false
59
+ t.datetime :revoked_at
59
60
 
60
61
  # The authorization server MAY issue a new refresh token, in which case
61
62
  # *the client MUST discard the old refresh token* and replace it with the
@@ -74,7 +75,17 @@ class CreateDoorkeeperTables < ActiveRecord::Migration<%= migration_version %>
74
75
  end
75
76
 
76
77
  add_index :oauth_access_tokens, :token, unique: true
77
- add_index :oauth_access_tokens, :refresh_token, unique: true
78
+
79
+ # See https://github.com/doorkeeper-gem/doorkeeper/issues/1592
80
+ if ActiveRecord::Base.connection.adapter_name == "SQLServer"
81
+ execute <<~SQL.squish
82
+ CREATE UNIQUE NONCLUSTERED INDEX index_oauth_access_tokens_on_refresh_token ON oauth_access_tokens(refresh_token)
83
+ WHERE refresh_token IS NOT NULL
84
+ SQL
85
+ else
86
+ add_index :oauth_access_tokens, :refresh_token, unique: true
87
+ end
88
+
78
89
  add_foreign_key(
79
90
  :oauth_access_tokens,
80
91
  :oauth_applications,
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveApplicationsSecretNotNullConstraint < ActiveRecord::Migration<%= migration_version %>
4
+ def change
5
+ change_column_null :oauth_applications, :secret, true
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doorkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.5.4
4
+ version: 5.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Elias Philipp
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-10-05 00:00:00.000000000 Z
14
+ date: 2024-12-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: railties
@@ -56,7 +56,7 @@ dependencies:
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  - !ruby/object:Gem::Dependency
59
- name: coveralls
59
+ name: coveralls_reborn
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
@@ -69,20 +69,6 @@ dependencies:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
- - !ruby/object:Gem::Dependency
73
- name: danger
74
- requirement: !ruby/object:Gem::Requirement
75
- requirements:
76
- - - "~>"
77
- - !ruby/object:Gem::Version
78
- version: '8.0'
79
- type: :development
80
- prerelease: false
81
- version_requirements: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - "~>"
84
- - !ruby/object:Gem::Version
85
- version: '8.0'
86
72
  - !ruby/object:Gem::Dependency
87
73
  name: database_cleaner
88
74
  requirement: !ruby/object:Gem::Requirement
@@ -117,14 +103,14 @@ dependencies:
117
103
  requirements:
118
104
  - - "~>"
119
105
  - !ruby/object:Gem::Version
120
- version: 0.9.3
106
+ version: 0.10.0
121
107
  type: :development
122
108
  prerelease: false
123
109
  version_requirements: !ruby/object:Gem::Requirement
124
110
  requirements:
125
111
  - - "~>"
126
112
  - !ruby/object:Gem::Version
127
- version: 0.9.3
113
+ version: 0.10.0
128
114
  - !ruby/object:Gem::Dependency
129
115
  name: grape
130
116
  requirement: !ruby/object:Gem::Requirement
@@ -167,6 +153,20 @@ dependencies:
167
153
  - - ">="
168
154
  - !ruby/object:Gem::Version
169
155
  version: '0'
156
+ - !ruby/object:Gem::Dependency
157
+ name: timecop
158
+ requirement: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
170
  description: Doorkeeper is an OAuth 2 provider for Rails and Grape.
171
171
  email:
172
172
  - bulaj.nikita@gmail.com
@@ -221,8 +221,10 @@ files:
221
221
  - lib/doorkeeper/models/application_mixin.rb
222
222
  - lib/doorkeeper/models/concerns/accessible.rb
223
223
  - lib/doorkeeper/models/concerns/expirable.rb
224
+ - lib/doorkeeper/models/concerns/expiration_time_sql_math.rb
224
225
  - lib/doorkeeper/models/concerns/orderable.rb
225
226
  - lib/doorkeeper/models/concerns/ownership.rb
227
+ - lib/doorkeeper/models/concerns/polymorphic_resource_owner.rb
226
228
  - lib/doorkeeper/models/concerns/resource_ownerable.rb
227
229
  - lib/doorkeeper/models/concerns/reusable.rb
228
230
  - lib/doorkeeper/models/concerns/revocable.rb
@@ -288,6 +290,8 @@ files:
288
290
  - lib/doorkeeper/request/refresh_token.rb
289
291
  - lib/doorkeeper/request/strategy.rb
290
292
  - lib/doorkeeper/request/token.rb
293
+ - lib/doorkeeper/revocable_tokens/revocable_access_token.rb
294
+ - lib/doorkeeper/revocable_tokens/revocable_refresh_token.rb
291
295
  - lib/doorkeeper/secret_storing/base.rb
292
296
  - lib/doorkeeper/secret_storing/bcrypt.rb
293
297
  - lib/doorkeeper/secret_storing/plain.rb
@@ -303,6 +307,7 @@ files:
303
307
  - lib/generators/doorkeeper/migration_generator.rb
304
308
  - lib/generators/doorkeeper/pkce_generator.rb
305
309
  - lib/generators/doorkeeper/previous_refresh_token_generator.rb
310
+ - lib/generators/doorkeeper/remove_applications_secret_not_null_constraint_generator.rb
306
311
  - lib/generators/doorkeeper/templates/README
307
312
  - lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb
308
313
  - lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb
@@ -311,6 +316,7 @@ files:
311
316
  - lib/generators/doorkeeper/templates/enable_polymorphic_resource_owner_migration.rb.erb
312
317
  - lib/generators/doorkeeper/templates/initializer.rb
313
318
  - lib/generators/doorkeeper/templates/migration.rb.erb
319
+ - lib/generators/doorkeeper/templates/remove_applications_secret_not_null_constraint.rb.erb
314
320
  - lib/generators/doorkeeper/views_generator.rb
315
321
  - vendor/assets/stylesheets/doorkeeper/bootstrap.min.css
316
322
  homepage: https://github.com/doorkeeper-gem/doorkeeper
@@ -322,6 +328,7 @@ metadata:
322
328
  source_code_uri: https://github.com/doorkeeper-gem/doorkeeper
323
329
  bug_tracker_uri: https://github.com/doorkeeper-gem/doorkeeper/issues
324
330
  documentation_uri: https://doorkeeper.gitbook.io/guides/
331
+ funding_uri: https://opencollective.com/doorkeeper-gem
325
332
  post_install_message: "Starting from 5.5.0 RC1 Doorkeeper requires client authentication
326
333
  for Resource Owner Password Grant\nas stated in the OAuth RFC. You have to create
327
334
  a new OAuth client (Doorkeeper::Application) if you didn't\nhave it before and use
@@ -337,14 +344,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
337
344
  requirements:
338
345
  - - ">="
339
346
  - !ruby/object:Gem::Version
340
- version: '2.5'
347
+ version: '2.7'
341
348
  required_rubygems_version: !ruby/object:Gem::Requirement
342
349
  requirements:
343
350
  - - ">="
344
351
  - !ruby/object:Gem::Version
345
352
  version: '0'
346
353
  requirements: []
347
- rubygems_version: 3.1.2
354
+ rubygems_version: 3.5.15
348
355
  signing_key:
349
356
  specification_version: 4
350
357
  summary: OAuth 2 provider for Rails and Grape