doorkeeper-mongodb 5.2.1 → 5.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -27
  3. data/lib/doorkeeper/orm/concerns/mongoid/ownership.rb +1 -1
  4. data/lib/doorkeeper/orm/concerns/mongoid/resource_ownerable.rb +1 -1
  5. data/lib/doorkeeper/orm/mongoid4.rb +18 -0
  6. data/lib/doorkeeper/orm/mongoid5.rb +18 -0
  7. data/lib/doorkeeper/orm/mongoid6.rb +18 -0
  8. data/lib/doorkeeper/orm/mongoid7.rb +18 -0
  9. data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +7 -6
  10. data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +8 -5
  11. data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +82 -5
  12. data/lib/doorkeeper-mongodb/mixins/mongoid/base_mixin.rb +0 -8
  13. data/lib/doorkeeper-mongodb/mixins/mongoid/json_serializable.rb +17 -0
  14. data/lib/doorkeeper-mongodb/version.rb +1 -1
  15. data/lib/doorkeeper-mongodb.rb +1 -0
  16. data/spec/controllers/application_metal_controller_spec.rb +4 -4
  17. data/spec/controllers/applications_controller_spec.rb +198 -202
  18. data/spec/controllers/authorizations_controller_spec.rb +32 -31
  19. data/spec/controllers/protected_resources_controller_spec.rb +10 -10
  20. data/spec/controllers/token_info_controller_spec.rb +1 -1
  21. data/spec/controllers/tokens_controller_spec.rb +105 -62
  22. data/spec/doorkeeper/redirect_uri_validator_spec.rb +183 -0
  23. data/spec/{lib → doorkeeper}/server_spec.rb +5 -4
  24. data/spec/{lib → doorkeeper}/stale_records_cleaner_spec.rb +8 -7
  25. data/spec/{version → doorkeeper}/version_spec.rb +3 -3
  26. data/spec/dummy/app/assets/config/manifest.js +0 -0
  27. data/spec/dummy/app/controllers/application_controller.rb +0 -0
  28. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
  29. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
  30. data/spec/dummy/app/controllers/home_controller.rb +0 -0
  31. data/spec/dummy/app/controllers/metal_controller.rb +0 -0
  32. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +0 -0
  34. data/spec/dummy/app/models/user.rb +0 -1
  35. data/spec/dummy/app/views/home/index.html.erb +0 -0
  36. data/spec/dummy/app/views/layouts/application.html.erb +0 -0
  37. data/spec/dummy/config/application.rb +0 -0
  38. data/spec/dummy/config/boot.rb +0 -0
  39. data/spec/dummy/config/database.yml +0 -0
  40. data/spec/dummy/config/environment.rb +0 -0
  41. data/spec/dummy/config/environments/development.rb +0 -0
  42. data/spec/dummy/config/environments/production.rb +0 -0
  43. data/spec/dummy/config/environments/test.rb +0 -0
  44. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
  45. data/spec/dummy/config/initializers/doorkeeper.rb +0 -0
  46. data/spec/dummy/config/initializers/secret_token.rb +0 -0
  47. data/spec/dummy/config/initializers/session_store.rb +0 -0
  48. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
  49. data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
  50. data/spec/dummy/config/mongo.yml +2 -2
  51. data/spec/dummy/config/routes.rb +0 -0
  52. data/spec/dummy/config.ru +0 -0
  53. data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
  54. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
  55. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
  56. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
  57. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
  58. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
  59. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
  60. data/spec/dummy/db/schema.rb +0 -0
  61. data/spec/dummy/public/404.html +0 -0
  62. data/spec/dummy/public/422.html +0 -0
  63. data/spec/dummy/public/500.html +0 -0
  64. data/spec/dummy/public/favicon.ico +0 -0
  65. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -0
  66. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
  67. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -0
  68. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -0
  69. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -0
  70. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -0
  71. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache +0 -0
  72. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -0
  73. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -0
  74. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
  75. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -0
  76. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache +0 -0
  77. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -0
  78. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache +0 -0
  79. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -0
  80. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache +0 -0
  81. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache +0 -0
  82. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -0
  83. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
  84. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache +0 -0
  85. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache +0 -0
  86. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
  87. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
  88. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
  89. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
  90. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
  91. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache +0 -0
  92. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache +0 -0
  93. data/spec/factories.rb +0 -0
  94. data/spec/grape/grape_integration_spec.rb +1 -1
  95. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  96. data/spec/lib/config_spec.rb +23 -12
  97. data/spec/lib/doorkeeper_spec.rb +4 -4
  98. data/spec/lib/models/expirable_spec.rb +9 -9
  99. data/spec/lib/models/reusable_spec.rb +2 -2
  100. data/spec/lib/models/revocable_spec.rb +4 -7
  101. data/spec/lib/models/scopes_spec.rb +7 -7
  102. data/spec/lib/models/secret_storable_spec.rb +9 -8
  103. data/spec/lib/oauth/authorization/uri_builder_spec.rb +23 -27
  104. data/spec/lib/oauth/authorization_code_request_spec.rb +6 -6
  105. data/spec/lib/oauth/base_request_spec.rb +11 -27
  106. data/spec/lib/oauth/base_response_spec.rb +2 -2
  107. data/spec/lib/oauth/client/credentials_spec.rb +25 -25
  108. data/spec/lib/oauth/client_credentials/creator_spec.rb +89 -91
  109. data/spec/lib/oauth/client_credentials/issuer_spec.rb +84 -86
  110. data/spec/lib/oauth/client_credentials/validation_spec.rb +72 -39
  111. data/spec/lib/oauth/client_credentials_integration_spec.rb +5 -5
  112. data/spec/lib/oauth/client_credentials_request_spec.rb +7 -10
  113. data/spec/lib/oauth/client_spec.rb +8 -8
  114. data/spec/lib/oauth/code_request_spec.rb +5 -5
  115. data/spec/lib/oauth/code_response_spec.rb +4 -4
  116. data/spec/lib/oauth/error_response_spec.rb +6 -5
  117. data/spec/lib/oauth/error_spec.rb +1 -1
  118. data/spec/lib/oauth/forbidden_token_response_spec.rb +2 -2
  119. data/spec/lib/oauth/helpers/scope_checker_spec.rb +37 -37
  120. data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
  121. data/spec/lib/oauth/helpers/uri_checker_spec.rb +54 -54
  122. data/spec/lib/oauth/invalid_request_response_spec.rb +6 -6
  123. data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
  124. data/spec/lib/oauth/password_access_token_request_spec.rb +10 -9
  125. data/spec/lib/oauth/pre_authorization_spec.rb +20 -8
  126. data/spec/lib/oauth/refresh_token_request_spec.rb +10 -10
  127. data/spec/lib/oauth/scopes_spec.rb +14 -14
  128. data/spec/lib/oauth/token_request_spec.rb +9 -9
  129. data/spec/lib/oauth/token_response_spec.rb +5 -5
  130. data/spec/lib/oauth/token_spec.rb +5 -5
  131. data/spec/lib/option_spec.rb +1 -1
  132. data/spec/lib/request/strategy_spec.rb +34 -37
  133. data/spec/lib/secret_storing/base_spec.rb +3 -2
  134. data/spec/lib/secret_storing/bcrypt_spec.rb +2 -1
  135. data/spec/lib/secret_storing/plain_spec.rb +2 -1
  136. data/spec/lib/secret_storing/sha256_hash_spec.rb +2 -1
  137. data/spec/models/doorkeeper/access_grant_spec.rb +7 -9
  138. data/spec/models/doorkeeper/access_token_spec.rb +20 -26
  139. data/spec/models/doorkeeper/application_spec.rb +83 -26
  140. data/spec/requests/applications/applications_request_spec.rb +91 -93
  141. data/spec/requests/applications/authorized_applications_spec.rb +0 -0
  142. data/spec/requests/endpoints/authorization_spec.rb +1 -1
  143. data/spec/requests/endpoints/token_spec.rb +22 -16
  144. data/spec/requests/flows/authorization_code_errors_spec.rb +12 -8
  145. data/spec/requests/flows/authorization_code_spec.rb +108 -79
  146. data/spec/requests/flows/client_credentials_spec.rb +57 -45
  147. data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -0
  148. data/spec/requests/flows/implicit_grant_spec.rb +4 -4
  149. data/spec/requests/flows/password_spec.rb +253 -213
  150. data/spec/requests/flows/refresh_token_spec.rb +53 -39
  151. data/spec/requests/flows/revoke_token_spec.rb +24 -24
  152. data/spec/requests/flows/skip_authorization_spec.rb +1 -1
  153. data/spec/requests/protected_resources/metal_spec.rb +2 -2
  154. data/spec/requests/protected_resources/private_api_spec.rb +0 -0
  155. data/spec/routing/custom_controller_routes_spec.rb +1 -1
  156. data/spec/routing/default_routes_spec.rb +1 -1
  157. data/spec/routing/scoped_routes_spec.rb +1 -1
  158. data/spec/spec_helper.rb +0 -0
  159. data/spec/spec_helper_integration.rb +0 -0
  160. data/spec/support/dependencies/factory_bot.rb +0 -0
  161. data/spec/support/doorkeeper_rspec.rb +0 -0
  162. data/spec/support/helpers/access_token_request_helper.rb +0 -0
  163. data/spec/support/helpers/authorization_request_helper.rb +0 -0
  164. data/spec/support/helpers/config_helper.rb +0 -0
  165. data/spec/support/helpers/model_helper.rb +0 -0
  166. data/spec/support/helpers/request_spec_helper.rb +1 -13
  167. data/spec/support/helpers/url_helper.rb +2 -2
  168. data/spec/support/orm/active_record.rb +0 -0
  169. data/spec/support/orm/mongoid4.rb +1 -1
  170. data/spec/support/orm/mongoid5.rb +1 -1
  171. data/spec/support/orm/mongoid6.rb +1 -1
  172. data/spec/support/orm/mongoid7.rb +1 -1
  173. data/spec/support/shared/controllers_shared_context.rb +5 -38
  174. data/spec/support/shared/hashing_shared_context.rb +4 -0
  175. data/spec/support/shared/models_shared_examples.rb +6 -6
  176. metadata +154 -167
  177. data/spec/dummy/log/test.log +0 -6108
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d0a38ac3113c658f1734bcafc4400ad23b43868a9eed97e7e132d05dd25a6a5
4
- data.tar.gz: 74e4f1804b455188ecb88401e934e5c8074d8d3bf9836e009c8ee7c24c0e961b
3
+ metadata.gz: f2798483ff1a989a1b8cefc2e94771e735c08f52879675c69b1808a912e2f730
4
+ data.tar.gz: ee24b6384a5378b6353a0a9006648feea656ab9d2c17d5fd596f6bf8637cadc9
5
5
  SHA512:
6
- metadata.gz: c8749be507eea672fb6cc7f19ce28595c9ef675a0b5bb1e739f2faf5aae4537fe0275d43c4acba3f7507225102ff2bca2796b58f630edc438e229d31ae4bd799
7
- data.tar.gz: 2b09f98f420b2993cbe903773a9cb5aac22281235a55515afbbb98c596a5ad2562612700b20d5a477fa52f4df924e7c9ff9ff913677947629dfe8a854432390d
6
+ metadata.gz: 260955b7a8b92403cf62913ee6eea0cd230b7f19cb030d8432a04916c821e392609641fc13f080e097703a1c96a8139df6e1800034e499b342c53940fdf40054
7
+ data.tar.gz: 3c79d4fdfbc2968716d2940c5f732a3476950cb5bcbc4120b040538fbd246299e398069a81fc5b2a001277af0fe2d4e48dcd08d0a7fc9a972de2e3e0ac82817d
data/README.md CHANGED
@@ -9,26 +9,15 @@ of doorkeeper-mongodb you are using in: https://github.com/doorkeeper-gem/doorke
9
9
 
10
10
  ## Installation
11
11
 
12
- `doorkeeper-mongodb` provides [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper) support to [Mongoid](https://github.com/mongodb/mongoid)
13
- (2, 3, 4 and 5 for doorkeeper-mongodb `3.0` and 4, 5, 6 and 7 for version `4.0` and higher). To start using it, add
14
- to your Gemfile:
12
+ `doorkeeper-mongodb` provides [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper) support
13
+ for [Mongoid](https://github.com/mongodb/mongoid) versions 6 and later. Earlier versions of Mongoid
14
+ are supported on earlier versions of `doorkeeper-mongodb`.
15
15
 
16
- ``` ruby
17
- # For Doorkeeper >= 5.2
18
- gem 'doorkeeper', '~> 5.2'
19
- gem 'doorkeeper-mongodb', '~> 5.2'
16
+ To start using it, add both `doorkeeper` and `doorkeeper-mongodb` to your Gemfile:
20
17
 
21
- # For Doorkeeper >= 5.0
22
- gem 'doorkeeper', '~> 5.0'
23
- gem 'doorkeeper-mongodb', '~> 5.0'
24
-
25
- # For Doorkeeper >= 4.4 && < 5.0
26
- gem 'doorkeeper', '~> 4.4'
27
- gem 'doorkeeper-mongodb', '~> 4.2'
28
-
29
- # For Doorkeeper < 4.4
30
- gem 'doorkeeper', '~> 4.3'
31
- gem 'doorkeeper-mongodb', '~> 4.1.0'
18
+ ```ruby
19
+ gem 'doorkeeper'
20
+ gem 'doorkeeper-mongodb'
32
21
 
33
22
  # or if you want to use cutting edge version:
34
23
  # gem 'doorkeeper-mongodb', github: 'doorkeeper-gem/doorkeeper-mongodb'
@@ -36,7 +25,9 @@ gem 'doorkeeper-mongodb', '~> 4.1.0'
36
25
 
37
26
  Run [doorkeeper’s installation generator]:
38
27
 
39
- rails generate doorkeeper:install
28
+ ```bash
29
+ $ rails generate doorkeeper:install
30
+ ```
40
31
 
41
32
  [doorkeeper’s installation generator]: https://github.com/doorkeeper-gem/doorkeeper#installation
42
33
 
@@ -45,20 +36,14 @@ This will install the doorkeeper initializer into
45
36
 
46
37
  Set the ORM configuration:
47
38
 
48
- ``` ruby
39
+ ```ruby
49
40
  Doorkeeper.configure do
50
41
  orm :mongoid7 # or any other version of mongoid
51
42
  end
52
43
  ```
53
44
 
54
- ## MongoMapper
55
-
56
- **NOTE**: Support of MongoMapper gem was dropped.
57
-
58
45
  ## Indexes
59
46
 
60
- ### Mongoid
61
-
62
47
  Make sure you create indexes for doorkeeper models. You can do this either by
63
48
  running `rake db:mongoid:create_indexes` or (if you're using Mongoid 2) by
64
49
  adding `autocreate_indexes: true` to your `config/mongoid.yml`
@@ -71,7 +56,7 @@ variables defined in `.travis.yml` file.
71
56
 
72
57
  To run locally, you need to choose a gemfile, with a command similar to:
73
58
 
74
- ```
59
+ ```bash
75
60
  $ export RAILS=5.1
76
61
  $ export BUNDLE_GEMFILE=$PWD/gemfiles/Gemfile.mongoid6.rb
77
62
  ```
@@ -13,7 +13,7 @@ module Doorkeeper
13
13
  belongs_to_options[:optional] = true if ::Mongoid::VERSION[0].to_i >= 6
14
14
 
15
15
  belongs_to :owner, belongs_to_options
16
- validates :owner, presence: true, if: :validate_owner?
16
+ validates_presence_of :owner, if: :validate_owner?
17
17
  end
18
18
 
19
19
  def validate_owner?
@@ -19,7 +19,7 @@ module Doorkeeper
19
19
  #
20
20
  def by_resource_owner(resource_owner)
21
21
  if DoorkeeperMongodb.doorkeeper_version?(5, 3) &&
22
- Doorkeeper.configuration.try(:polymorphic_resource_owner?)
22
+ Doorkeeper.configuration.try(:polymorphic_resource_owner?)
23
23
  where(resource_owner: resource_owner)
24
24
  else
25
25
  where(resource_owner_id: resource_owner_id_for(resource_owner))
@@ -5,7 +5,22 @@ require "active_support/lazy_load_hooks"
5
5
  module Doorkeeper
6
6
  module Orm
7
7
  module Mongoid4
8
+ def self.run_hooks
9
+ lazy_load do
10
+ require "doorkeeper/orm/mongoid4/access_grant"
11
+ require "doorkeeper/orm/mongoid4/access_token"
12
+ require "doorkeeper/orm/mongoid4/application"
13
+ require "doorkeeper/orm/mongoid4/stale_records_cleaner"
14
+ require "doorkeeper/orm/concerns/mongoid/ownership"
15
+ Doorkeeper::Application.include Doorkeeper::Orm::Concerns::Mongoid::Ownership
16
+ end
17
+ @initialized_hooks = true
18
+ end
19
+
20
+ # @deprecated
8
21
  def self.initialize_models!
22
+ return if @initialized_hooks
23
+
9
24
  lazy_load do
10
25
  require "doorkeeper/orm/mongoid4/access_grant"
11
26
  require "doorkeeper/orm/mongoid4/access_token"
@@ -14,7 +29,10 @@ module Doorkeeper
14
29
  end
15
30
  end
16
31
 
32
+ # @deprecated
17
33
  def self.initialize_application_owner!
34
+ return if @initialized_hooks
35
+
18
36
  lazy_load do
19
37
  require "doorkeeper/orm/concerns/mongoid/ownership"
20
38
 
@@ -5,7 +5,22 @@ require "active_support/lazy_load_hooks"
5
5
  module Doorkeeper
6
6
  module Orm
7
7
  module Mongoid5
8
+ def self.run_hooks
9
+ lazy_load do
10
+ require "doorkeeper/orm/mongoid5/access_grant"
11
+ require "doorkeeper/orm/mongoid5/access_token"
12
+ require "doorkeeper/orm/mongoid5/application"
13
+ require "doorkeeper/orm/mongoid5/stale_records_cleaner"
14
+ require "doorkeeper/orm/concerns/mongoid/ownership"
15
+ Doorkeeper::Application.include Doorkeeper::Orm::Concerns::Mongoid::Ownership
16
+ end
17
+ @initialized_hooks = true
18
+ end
19
+
20
+ # @deprecated
8
21
  def self.initialize_models!
22
+ return if @initialized_hooks
23
+
9
24
  lazy_load do
10
25
  require "doorkeeper/orm/mongoid5/access_grant"
11
26
  require "doorkeeper/orm/mongoid5/access_token"
@@ -14,7 +29,10 @@ module Doorkeeper
14
29
  end
15
30
  end
16
31
 
32
+ # @deprecated
17
33
  def self.initialize_application_owner!
34
+ return if @initialized_hooks
35
+
18
36
  lazy_load do
19
37
  require "doorkeeper/orm/concerns/mongoid/ownership"
20
38
 
@@ -5,7 +5,22 @@ require "active_support/lazy_load_hooks"
5
5
  module Doorkeeper
6
6
  module Orm
7
7
  module Mongoid6
8
+ def self.run_hooks
9
+ lazy_load do
10
+ require "doorkeeper/orm/mongoid6/access_grant"
11
+ require "doorkeeper/orm/mongoid6/access_token"
12
+ require "doorkeeper/orm/mongoid6/application"
13
+ require "doorkeeper/orm/mongoid6/stale_records_cleaner"
14
+ require "doorkeeper/orm/concerns/mongoid/ownership"
15
+ Doorkeeper::Application.include Doorkeeper::Orm::Concerns::Mongoid::Ownership
16
+ end
17
+ @initialized_hooks = true
18
+ end
19
+
20
+ # @deprecated
8
21
  def self.initialize_models!
22
+ return if @initialized_hooks
23
+
9
24
  lazy_load do
10
25
  require "doorkeeper/orm/mongoid6/access_grant"
11
26
  require "doorkeeper/orm/mongoid6/access_token"
@@ -14,7 +29,10 @@ module Doorkeeper
14
29
  end
15
30
  end
16
31
 
32
+ # @deprecated
17
33
  def self.initialize_application_owner!
34
+ return if @initialized_hooks
35
+
18
36
  lazy_load do
19
37
  require "doorkeeper/orm/concerns/mongoid/ownership"
20
38
 
@@ -5,7 +5,22 @@ require "active_support/lazy_load_hooks"
5
5
  module Doorkeeper
6
6
  module Orm
7
7
  module Mongoid7
8
+ def self.run_hooks
9
+ lazy_load do
10
+ require "doorkeeper/orm/mongoid7/access_grant"
11
+ require "doorkeeper/orm/mongoid7/access_token"
12
+ require "doorkeeper/orm/mongoid7/application"
13
+ require "doorkeeper/orm/mongoid7/stale_records_cleaner"
14
+ require "doorkeeper/orm/concerns/mongoid/ownership"
15
+ Doorkeeper::Application.include Doorkeeper::Orm::Concerns::Mongoid::Ownership
16
+ end
17
+ @initialized_hooks = true
18
+ end
19
+
20
+ # @deprecated
8
21
  def self.initialize_models!
22
+ return if @initialized_hooks
23
+
9
24
  lazy_load do
10
25
  require "doorkeeper/orm/mongoid7/access_grant"
11
26
  require "doorkeeper/orm/mongoid7/access_token"
@@ -14,7 +29,10 @@ module Doorkeeper
14
29
  end
15
30
  end
16
31
 
32
+ # @deprecated
17
33
  def self.initialize_application_owner!
34
+ return if @initialized_hooks
35
+
18
36
  lazy_load do
19
37
  require "doorkeeper/orm/concerns/mongoid/ownership"
20
38
 
@@ -14,6 +14,7 @@ module DoorkeeperMongodb
14
14
  include Doorkeeper::Models::SecretStorable
15
15
  include Doorkeeper::Orm::Concerns::Mongoid::ResourceOwnerable
16
16
  include BaseMixin
17
+ include JsonSerializable
17
18
 
18
19
  included do
19
20
  belongs_to_opts = {
@@ -35,8 +36,9 @@ module DoorkeeperMongodb
35
36
  belongs_to :resource_owner, polymorphic: true
36
37
  end
37
38
 
38
- validates :resource_owner_id, :application_id, :token, :expires_in, :redirect_uri, presence: true
39
- validates :token, uniqueness: true
39
+ validates_presence_of :resource_owner_id, :application_id, :token,
40
+ :expires_in, :redirect_uri
41
+ validates_uniqueness_of :token
40
42
 
41
43
  before_validation :generate_token, on: :create
42
44
  end
@@ -122,15 +124,14 @@ module DoorkeeperMongodb
122
124
 
123
125
  # @param code_verifier [#to_s] a one time use value (any object that responds to `#to_s`)
124
126
  #
125
- # @return [#to_s] An encoded code challenge based on the provided verifier suitable for PKCE validation
127
+ # @return [#to_s] An encoded code challenge based on the provided verifier suitable
128
+ # for PKCE validation
126
129
  def generate_code_challenge(code_verifier)
127
130
  padded_result = Base64.urlsafe_encode64(Digest::SHA256.digest(code_verifier))
128
131
  padded_result.split("=")[0] # Remove any trailing '='
129
132
  end
130
133
 
131
- def pkce_supported?
132
- new.pkce_supported?
133
- end
134
+ delegate :pkce_supported?, to: :new
134
135
 
135
136
  ##
136
137
  # Determines the secret storing transformer
@@ -15,6 +15,7 @@ module DoorkeeperMongodb
15
15
  include Doorkeeper::Models::SecretStorable
16
16
  include Doorkeeper::Orm::Concerns::Mongoid::ResourceOwnerable
17
17
  include BaseMixin
18
+ include JsonSerializable
18
19
 
19
20
  included do
20
21
  belongs_to_opts = {
@@ -40,8 +41,9 @@ module DoorkeeperMongodb
40
41
  belongs_to :resource_owner, opts
41
42
  end
42
43
 
43
- validates :token, presence: true, uniqueness: true
44
- validates :refresh_token, uniqueness: true, if: :use_refresh_token?
44
+ validates_presence_of :token
45
+ validates_uniqueness_of :token
46
+ validates_uniqueness_of :refresh_token, if: :use_refresh_token?
45
47
 
46
48
  # @attr_writer [Boolean, nil] use_refresh_token
47
49
  # indicates the possibility of using refresh token
@@ -367,10 +369,10 @@ module DoorkeeperMongodb
367
369
  # and clears `:previous_refresh_token` attribute.
368
370
  #
369
371
  def revoke_previous_refresh_token!
370
- return unless self.class.refresh_token_revoked_on_use?
372
+ return if !self.class.refresh_token_revoked_on_use? || previous_refresh_token.blank?
371
373
 
372
374
  old_refresh_token&.revoke
373
- update(previous_refresh_token: "")
375
+ update_attribute(:previous_refresh_token, "")
374
376
  end
375
377
 
376
378
  private
@@ -418,7 +420,8 @@ module DoorkeeperMongodb
418
420
 
419
421
  return generator if generator.respond_to?(:generate)
420
422
 
421
- raise Doorkeeper::Errors::UnableToGenerateToken, "#{generator} does not respond to `.generate`."
423
+ raise Doorkeeper::Errors::UnableToGenerateToken,
424
+ "#{generator} does not respond to `.generate`."
422
425
  rescue NameError
423
426
  raise Doorkeeper::Errors::TokenGeneratorNotFound, "#{generator_name} not found"
424
427
  end
@@ -36,8 +36,8 @@ module DoorkeeperMongodb
36
36
  has_many :access_grants, has_many_options.merge(class_name: access_grants_class_name)
37
37
  has_many :access_tokens, has_many_options.merge(class_name: access_tokens_class_name)
38
38
 
39
- validates :name, :secret, :uid, presence: true
40
- validates :uid, uniqueness: true
39
+ validates_presence_of :name, :secret, :uid
40
+ validates_uniqueness_of :uid
41
41
 
42
42
  # Before Doorkeeper 5.2.3
43
43
  if defined?(::RedirectUriValidator)
@@ -46,11 +46,87 @@ module DoorkeeperMongodb
46
46
  validates :redirect_uri, "doorkeeper/redirect_uri": true
47
47
  end
48
48
 
49
- validates :confidential, inclusion: { in: [true, false] }
49
+ validates_inclusion_of :confidential, in: [true, false]
50
50
 
51
51
  validate :scopes_match_configured, if: :enforce_scopes?
52
52
 
53
53
  before_validation :generate_uid, :generate_secret, on: :create
54
+
55
+ # Represents client as set of it's attributes in JSON format.
56
+ # This is the right way how we want to override ActiveRecord #to_json.
57
+ #
58
+ # Respects privacy settings and serializes minimum set of attributes
59
+ # for public/private clients and full set for authorized owners.
60
+ #
61
+ # @return [Hash] entity attributes for JSON
62
+ #
63
+ def as_json(options = {})
64
+ # if application belongs to some owner we need to check if it's the same as
65
+ # the one passed in the options or check if we render the client as an owner
66
+ if (respond_to?(:owner) && owner && owner == options[:current_resource_owner]) ||
67
+ options[:as_owner]
68
+ # Owners can see all the client attributes, fallback to ActiveModel serialization
69
+ super
70
+ else
71
+ # if application has no owner or it's owner doesn't match one from the options
72
+ # we render only minimum set of attributes that could be exposed to a public
73
+ only = extract_serializable_attributes(options)
74
+ super(options.merge(only: only))
75
+ end
76
+ end
77
+
78
+ def serializable_hash(options = nil)
79
+ hash = super
80
+ if hash.key?("_id")
81
+ hash["id"] = hash.delete("_id")
82
+ elsif options && Array.wrap(options[:only].map(&:to_sym)).include?(:id)
83
+ hash["id"] = id.to_s
84
+ end
85
+ hash
86
+ end
87
+
88
+ # Helper method to extract collection of serializable attribute names
89
+ # considering serialization options (like `only`, `except` and so on).
90
+ #
91
+ # @param options [Hash] serialization options
92
+ #
93
+ # @return [Array<String>]
94
+ # collection of attributes to be serialized using #as_json
95
+ #
96
+ def extract_serializable_attributes(options = {})
97
+ opts = options.try(:dup) || {}
98
+ only = Array.wrap(opts[:only]).map(&:to_s)
99
+
100
+ only = if only.blank?
101
+ serializable_attributes
102
+ else
103
+ only & serializable_attributes
104
+ end
105
+
106
+ only -= Array.wrap(opts[:except]).map(&:to_s) if opts.key?(:except)
107
+ only.uniq
108
+ end
109
+
110
+ # We need to hook into this method to allow serializing plan-text secrets
111
+ # when secrets hashing enabled.
112
+ #
113
+ # @param key [String] attribute name
114
+ #
115
+ def read_attribute_for_serialization(key)
116
+ return super unless key.to_s == "secret"
117
+
118
+ plaintext_secret || secret
119
+ end
120
+
121
+ # Collection of attributes that could be serialized for public.
122
+ # Override this method if you need additional attributes to be serialized.
123
+ #
124
+ # @return [Array<String>] collection of serializable attributes
125
+ def serializable_attributes
126
+ attributes = %w[id name created_at]
127
+ attributes << "uid" unless confidential?
128
+ attributes
129
+ end
54
130
  end
55
131
 
56
132
  module ClassMethods
@@ -166,7 +242,7 @@ module DoorkeeperMongodb
166
242
  end
167
243
 
168
244
  def generate_secret
169
- return unless secret.blank?
245
+ return if secret.present?
170
246
 
171
247
  @raw_secret = UniqueToken.generate
172
248
  secret_strategy.store_secret(self, :secret, @raw_secret)
@@ -174,7 +250,8 @@ module DoorkeeperMongodb
174
250
 
175
251
  def scopes_match_configured
176
252
  if scopes.present? &&
177
- !ScopeChecker.valid?(scope_str: scopes.to_s, server_scopes: Doorkeeper.configuration.scopes)
253
+ !ScopeChecker.valid?(scope_str: scopes.to_s,
254
+ server_scopes: Doorkeeper.configuration.scopes,)
178
255
  errors.add(:scopes, :not_match_configured)
179
256
  end
180
257
  end
@@ -17,14 +17,6 @@ module DoorkeeperMongodb
17
17
  nil
18
18
  end
19
19
  end
20
-
21
- def as_json(*args)
22
- json_response = super
23
-
24
- json_response["id"] = json_response["_id"]
25
-
26
- json_response
27
- end
28
20
  end
29
21
  end
30
22
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DoorkeeperMongodb
4
+ module Mixins
5
+ module Mongoid
6
+ module JsonSerializable
7
+ extend ActiveSupport::Concern
8
+
9
+ def as_json(*args)
10
+ json = super
11
+ json["id"] = json.delete("_id") if json.key?("_id")
12
+ json
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -9,7 +9,7 @@ module DoorkeeperMongodb
9
9
  # Semver
10
10
  MAJOR = 5
11
11
  MINOR = 2
12
- TINY = 1
12
+ TINY = 3
13
13
 
14
14
  # Full version number
15
15
  STRING = [MAJOR, MINOR, TINY].compact.join(".")
@@ -17,6 +17,7 @@ require "doorkeeper/orm/concerns/mongoid/ownership"
17
17
  require "doorkeeper/orm/concerns/mongoid/resource_ownerable"
18
18
 
19
19
  require "doorkeeper-mongodb/mixins/mongoid/base_mixin"
20
+ require "doorkeeper-mongodb/mixins/mongoid/json_serializable"
20
21
  require "doorkeeper-mongodb/mixins/mongoid/access_grant_mixin"
21
22
  require "doorkeeper-mongodb/mixins/mongoid/access_token_mixin"
22
23
  require "doorkeeper-mongodb/mixins/mongoid/application_mixin"
@@ -2,8 +2,8 @@
2
2
 
3
3
  require "spec_helper_integration"
4
4
 
5
- describe Doorkeeper::ApplicationMetalController do
6
- controller(Doorkeeper::ApplicationMetalController) do
5
+ RSpec.describe Doorkeeper::ApplicationMetalController do
6
+ controller(described_class) do
7
7
  def index
8
8
  render json: {}, status: 200
9
9
  end
@@ -23,7 +23,7 @@ describe Doorkeeper::ApplicationMetalController do
23
23
  describe "enforce_content_type" do
24
24
  before { allow(Doorkeeper.config).to receive(:enforce_content_type).and_return(flag) }
25
25
 
26
- context "enabled" do
26
+ context "when enabled" do
27
27
  let(:flag) { true }
28
28
 
29
29
  it "returns a 200 for the requests without body" do
@@ -42,7 +42,7 @@ describe Doorkeeper::ApplicationMetalController do
42
42
  end
43
43
  end
44
44
 
45
- context "disabled" do
45
+ context "when disabled" do
46
46
  let(:flag) { false }
47
47
 
48
48
  it "returns a 200 for the correct media type" do