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.
- checksums.yaml +4 -4
- data/README.md +12 -27
- data/lib/doorkeeper/orm/concerns/mongoid/ownership.rb +1 -1
- data/lib/doorkeeper/orm/concerns/mongoid/resource_ownerable.rb +1 -1
- data/lib/doorkeeper/orm/mongoid4.rb +18 -0
- data/lib/doorkeeper/orm/mongoid5.rb +18 -0
- data/lib/doorkeeper/orm/mongoid6.rb +18 -0
- data/lib/doorkeeper/orm/mongoid7.rb +18 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +7 -6
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +8 -5
- data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +82 -5
- data/lib/doorkeeper-mongodb/mixins/mongoid/base_mixin.rb +0 -8
- data/lib/doorkeeper-mongodb/mixins/mongoid/json_serializable.rb +17 -0
- data/lib/doorkeeper-mongodb/version.rb +1 -1
- data/lib/doorkeeper-mongodb.rb +1 -0
- data/spec/controllers/application_metal_controller_spec.rb +4 -4
- data/spec/controllers/applications_controller_spec.rb +198 -202
- data/spec/controllers/authorizations_controller_spec.rb +32 -31
- data/spec/controllers/protected_resources_controller_spec.rb +10 -10
- data/spec/controllers/token_info_controller_spec.rb +1 -1
- data/spec/controllers/tokens_controller_spec.rb +105 -62
- data/spec/doorkeeper/redirect_uri_validator_spec.rb +183 -0
- data/spec/{lib → doorkeeper}/server_spec.rb +5 -4
- data/spec/{lib → doorkeeper}/stale_records_cleaner_spec.rb +8 -7
- data/spec/{version → doorkeeper}/version_spec.rb +3 -3
- data/spec/dummy/app/assets/config/manifest.js +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/controllers/home_controller.rb +0 -0
- data/spec/dummy/app/controllers/metal_controller.rb +0 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -0
- data/spec/dummy/app/models/user.rb +0 -1
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -0
- data/spec/dummy/config/application.rb +0 -0
- data/spec/dummy/config/boot.rb +0 -0
- data/spec/dummy/config/database.yml +0 -0
- data/spec/dummy/config/environment.rb +0 -0
- data/spec/dummy/config/environments/development.rb +0 -0
- data/spec/dummy/config/environments/production.rb +0 -0
- data/spec/dummy/config/environments/test.rb +0 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -0
- data/spec/dummy/config/initializers/secret_token.rb +0 -0
- data/spec/dummy/config/initializers/session_store.rb +0 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
- data/spec/dummy/config/mongo.yml +2 -2
- data/spec/dummy/config/routes.rb +0 -0
- data/spec/dummy/config.ru +0 -0
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
- data/spec/dummy/db/schema.rb +0 -0
- data/spec/dummy/public/404.html +0 -0
- data/spec/dummy/public/422.html +0 -0
- data/spec/dummy/public/500.html +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache +0 -0
- data/spec/factories.rb +0 -0
- data/spec/grape/grape_integration_spec.rb +1 -1
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +23 -12
- data/spec/lib/doorkeeper_spec.rb +4 -4
- data/spec/lib/models/expirable_spec.rb +9 -9
- data/spec/lib/models/reusable_spec.rb +2 -2
- data/spec/lib/models/revocable_spec.rb +4 -7
- data/spec/lib/models/scopes_spec.rb +7 -7
- data/spec/lib/models/secret_storable_spec.rb +9 -8
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +23 -27
- data/spec/lib/oauth/authorization_code_request_spec.rb +6 -6
- data/spec/lib/oauth/base_request_spec.rb +11 -27
- data/spec/lib/oauth/base_response_spec.rb +2 -2
- data/spec/lib/oauth/client/credentials_spec.rb +25 -25
- data/spec/lib/oauth/client_credentials/creator_spec.rb +89 -91
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +84 -86
- data/spec/lib/oauth/client_credentials/validation_spec.rb +72 -39
- data/spec/lib/oauth/client_credentials_integration_spec.rb +5 -5
- data/spec/lib/oauth/client_credentials_request_spec.rb +7 -10
- data/spec/lib/oauth/client_spec.rb +8 -8
- data/spec/lib/oauth/code_request_spec.rb +5 -5
- data/spec/lib/oauth/code_response_spec.rb +4 -4
- data/spec/lib/oauth/error_response_spec.rb +6 -5
- data/spec/lib/oauth/error_spec.rb +1 -1
- data/spec/lib/oauth/forbidden_token_response_spec.rb +2 -2
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +37 -37
- data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +54 -54
- data/spec/lib/oauth/invalid_request_response_spec.rb +6 -6
- data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +10 -9
- data/spec/lib/oauth/pre_authorization_spec.rb +20 -8
- data/spec/lib/oauth/refresh_token_request_spec.rb +10 -10
- data/spec/lib/oauth/scopes_spec.rb +14 -14
- data/spec/lib/oauth/token_request_spec.rb +9 -9
- data/spec/lib/oauth/token_response_spec.rb +5 -5
- data/spec/lib/oauth/token_spec.rb +5 -5
- data/spec/lib/option_spec.rb +1 -1
- data/spec/lib/request/strategy_spec.rb +34 -37
- data/spec/lib/secret_storing/base_spec.rb +3 -2
- data/spec/lib/secret_storing/bcrypt_spec.rb +2 -1
- data/spec/lib/secret_storing/plain_spec.rb +2 -1
- data/spec/lib/secret_storing/sha256_hash_spec.rb +2 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +7 -9
- data/spec/models/doorkeeper/access_token_spec.rb +20 -26
- data/spec/models/doorkeeper/application_spec.rb +83 -26
- data/spec/requests/applications/applications_request_spec.rb +91 -93
- data/spec/requests/applications/authorized_applications_spec.rb +0 -0
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +22 -16
- data/spec/requests/flows/authorization_code_errors_spec.rb +12 -8
- data/spec/requests/flows/authorization_code_spec.rb +108 -79
- data/spec/requests/flows/client_credentials_spec.rb +57 -45
- data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -0
- data/spec/requests/flows/implicit_grant_spec.rb +4 -4
- data/spec/requests/flows/password_spec.rb +253 -213
- data/spec/requests/flows/refresh_token_spec.rb +53 -39
- data/spec/requests/flows/revoke_token_spec.rb +24 -24
- data/spec/requests/flows/skip_authorization_spec.rb +1 -1
- data/spec/requests/protected_resources/metal_spec.rb +2 -2
- data/spec/requests/protected_resources/private_api_spec.rb +0 -0
- data/spec/routing/custom_controller_routes_spec.rb +1 -1
- data/spec/routing/default_routes_spec.rb +1 -1
- data/spec/routing/scoped_routes_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -0
- data/spec/spec_helper_integration.rb +0 -0
- data/spec/support/dependencies/factory_bot.rb +0 -0
- data/spec/support/doorkeeper_rspec.rb +0 -0
- data/spec/support/helpers/access_token_request_helper.rb +0 -0
- data/spec/support/helpers/authorization_request_helper.rb +0 -0
- data/spec/support/helpers/config_helper.rb +0 -0
- data/spec/support/helpers/model_helper.rb +0 -0
- data/spec/support/helpers/request_spec_helper.rb +1 -13
- data/spec/support/helpers/url_helper.rb +2 -2
- data/spec/support/orm/active_record.rb +0 -0
- data/spec/support/orm/mongoid4.rb +1 -1
- data/spec/support/orm/mongoid5.rb +1 -1
- data/spec/support/orm/mongoid6.rb +1 -1
- data/spec/support/orm/mongoid7.rb +1 -1
- data/spec/support/shared/controllers_shared_context.rb +5 -38
- data/spec/support/shared/hashing_shared_context.rb +4 -0
- data/spec/support/shared/models_shared_examples.rb +6 -6
- metadata +154 -167
- data/spec/dummy/log/test.log +0 -6108
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2798483ff1a989a1b8cefc2e94771e735c08f52879675c69b1808a912e2f730
|
4
|
+
data.tar.gz: ee24b6384a5378b6353a0a9006648feea656ab9d2c17d5fd596f6bf8637cadc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
22
|
-
gem 'doorkeeper'
|
23
|
-
gem 'doorkeeper-mongodb'
|
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
|
-
|
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
|
-
```
|
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
|
-
|
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
|
-
|
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
|
-
|
39
|
-
|
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
|
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
|
-
|
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
|
-
|
44
|
-
|
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
|
372
|
+
return if !self.class.refresh_token_revoked_on_use? || previous_refresh_token.blank?
|
371
373
|
|
372
374
|
old_refresh_token&.revoke
|
373
|
-
|
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,
|
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
|
-
|
40
|
-
|
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
|
-
|
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
|
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,
|
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
|
@@ -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
|
data/lib/doorkeeper-mongodb.rb
CHANGED
@@ -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(
|
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
|