doorkeeper 5.2.0 → 5.3.0
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.
- checksums.yaml +4 -4
- data/Appraisals +2 -2
- data/CHANGELOG.md +40 -2
- data/Gemfile +2 -2
- data/app/controllers/doorkeeper/application_controller.rb +2 -2
- data/app/controllers/doorkeeper/application_metal_controller.rb +2 -2
- data/app/controllers/doorkeeper/applications_controller.rb +0 -1
- data/app/controllers/doorkeeper/authorizations_controller.rb +2 -2
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +2 -2
- data/config/locales/en.yml +1 -1
- data/gemfiles/rails_5_0.gemfile +2 -2
- data/gemfiles/rails_5_1.gemfile +2 -2
- data/gemfiles/rails_5_2.gemfile +2 -2
- data/gemfiles/rails_6_0.gemfile +2 -2
- data/gemfiles/rails_master.gemfile +2 -2
- data/lib/doorkeeper/config.rb +71 -38
- data/lib/doorkeeper/grape/helpers.rb +1 -1
- data/lib/doorkeeper/helpers/controller.rb +12 -8
- data/lib/doorkeeper/models/access_grant_mixin.rb +7 -6
- data/lib/doorkeeper/models/access_token_mixin.rb +56 -18
- data/lib/doorkeeper/models/application_mixin.rb +3 -3
- data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
- data/lib/doorkeeper/models/concerns/reusable.rb +1 -1
- data/lib/doorkeeper/models/concerns/revocable.rb +0 -27
- data/lib/doorkeeper/oauth/authorization/code.rb +4 -4
- data/lib/doorkeeper/oauth/authorization/token.rb +9 -6
- data/lib/doorkeeper/oauth/authorization_code_request.rb +13 -6
- data/lib/doorkeeper/oauth/base_request.rb +8 -4
- data/lib/doorkeeper/oauth/client.rb +7 -8
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +16 -9
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +7 -7
- data/lib/doorkeeper/oauth/client_credentials/{validation.rb → validator.rb} +4 -4
- data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
- data/lib/doorkeeper/oauth/code_response.rb +2 -2
- data/lib/doorkeeper/oauth/error.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +5 -5
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +7 -5
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +8 -5
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
- data/lib/doorkeeper/oauth/invalid_request_response.rb +3 -3
- data/lib/doorkeeper/oauth/invalid_token_response.rb +5 -2
- data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
- data/lib/doorkeeper/oauth/pre_authorization.rb +12 -7
- data/lib/doorkeeper/oauth/refresh_token_request.rb +5 -5
- data/lib/doorkeeper/oauth/token.rb +2 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +6 -6
- data/lib/doorkeeper/orm/active_record/access_grant.rb +4 -43
- data/lib/doorkeeper/orm/active_record/access_token.rb +4 -35
- data/lib/doorkeeper/orm/active_record/application.rb +5 -89
- data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +53 -0
- data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +47 -0
- data/lib/doorkeeper/orm/active_record/mixins/application.rb +128 -0
- data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +3 -3
- data/lib/doorkeeper/orm/active_record.rb +3 -4
- data/lib/doorkeeper/rails/helpers.rb +4 -4
- data/lib/doorkeeper/rails/routes.rb +5 -7
- data/lib/doorkeeper/rake/db.rake +3 -3
- data/lib/doorkeeper/request/authorization_code.rb +3 -3
- data/lib/doorkeeper/request/client_credentials.rb +2 -2
- data/lib/doorkeeper/request/password.rb +2 -2
- data/lib/doorkeeper/request/refresh_token.rb +3 -3
- data/lib/doorkeeper/request.rb +1 -1
- data/lib/doorkeeper/server.rb +1 -1
- data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +2 -3
- data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +1 -1
- data/lib/generators/doorkeeper/migration_generator.rb +1 -1
- data/lib/generators/doorkeeper/pkce_generator.rb +1 -1
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +2 -2
- data/lib/generators/doorkeeper/templates/initializer.rb +39 -0
- data/spec/controllers/application_metal_controller_spec.rb +1 -1
- data/spec/controllers/applications_controller_spec.rb +3 -2
- data/spec/controllers/authorizations_controller_spec.rb +20 -18
- data/spec/controllers/protected_resources_controller_spec.rb +25 -17
- data/spec/controllers/token_info_controller_spec.rb +1 -1
- data/spec/controllers/tokens_controller_spec.rb +1 -1
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -3
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +1 -1
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +1 -1
- data/spec/generators/install_generator_spec.rb +1 -1
- data/spec/generators/previous_refresh_token_generator_spec.rb +2 -2
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +62 -7
- data/spec/lib/doorkeeper_spec.rb +1 -1
- data/spec/lib/models/revocable_spec.rb +3 -3
- data/spec/lib/oauth/authorization_code_request_spec.rb +127 -123
- data/spec/lib/oauth/base_request_spec.rb +160 -158
- data/spec/lib/oauth/base_response_spec.rb +27 -29
- data/spec/lib/oauth/client/credentials_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials/creator_spec.rb +42 -5
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +12 -12
- data/spec/lib/oauth/client_credentials/validation_spec.rb +4 -4
- data/spec/lib/oauth/client_credentials_integration_spec.rb +16 -18
- data/spec/lib/oauth/client_credentials_request_spec.rb +78 -80
- data/spec/lib/oauth/client_spec.rb +26 -26
- data/spec/lib/oauth/code_request_spec.rb +34 -34
- data/spec/lib/oauth/code_response_spec.rb +21 -25
- data/spec/lib/oauth/error_response_spec.rb +42 -44
- data/spec/lib/oauth/error_spec.rb +12 -14
- data/spec/lib/oauth/forbidden_token_response_spec.rb +11 -13
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +30 -18
- data/spec/lib/oauth/invalid_request_response_spec.rb +48 -50
- data/spec/lib/oauth/invalid_token_response_spec.rb +32 -34
- data/spec/lib/oauth/password_access_token_request_spec.rb +145 -147
- data/spec/lib/oauth/pre_authorization_spec.rb +159 -161
- data/spec/lib/oauth/refresh_token_request_spec.rb +138 -139
- data/spec/lib/oauth/scopes_spec.rb +104 -106
- data/spec/lib/oauth/token_request_spec.rb +115 -111
- data/spec/lib/oauth/token_response_spec.rb +71 -73
- data/spec/lib/oauth/token_spec.rb +121 -123
- data/spec/models/doorkeeper/access_grant_spec.rb +21 -4
- data/spec/models/doorkeeper/access_token_spec.rb +42 -11
- data/spec/models/doorkeeper/application_spec.rb +114 -77
- data/spec/requests/applications/applications_request_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +5 -3
- data/spec/requests/flows/authorization_code_spec.rb +34 -22
- data/spec/requests/flows/client_credentials_spec.rb +1 -1
- data/spec/requests/flows/password_spec.rb +32 -12
- data/spec/requests/flows/refresh_token_spec.rb +19 -19
- data/spec/requests/flows/revoke_token_spec.rb +18 -12
- data/spec/spec_helper.rb +1 -4
- data/spec/support/shared/controllers_shared_context.rb +33 -23
- data/spec/validators/redirect_uri_validator_spec.rb +1 -1
- metadata +6 -5
- data/spec/support/http_method_shim.rb +0 -29
|
@@ -7,152 +7,150 @@ module Doorkeeper
|
|
|
7
7
|
class AccessToken
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let(:request) { double.as_null_object }
|
|
12
|
+
describe Doorkeeper::OAuth::Token do
|
|
13
|
+
describe ".from_request" do
|
|
14
|
+
let(:request) { double.as_null_object }
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
let(:method) do
|
|
17
|
+
->(*) { "token-value" }
|
|
18
|
+
end
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
it "accepts anything that responds to #call" do
|
|
21
|
+
expect(method).to receive(:call).with(request)
|
|
22
|
+
described_class.from_request request, method
|
|
23
|
+
end
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
it "delegates methods received as symbols to described_class class" do
|
|
26
|
+
expect(described_class).to receive(:from_params).with(request)
|
|
27
|
+
described_class.from_request request, :from_params
|
|
28
|
+
end
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
it "stops at the first credentials found" do
|
|
31
|
+
not_called_method = double
|
|
32
|
+
expect(not_called_method).not_to receive(:call)
|
|
33
|
+
described_class.from_request request, ->(_r) {}, method, not_called_method
|
|
34
|
+
end
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
it "returns the credential from extractor method" do
|
|
37
|
+
credentials = described_class.from_request request, method
|
|
38
|
+
expect(credentials).to eq("token-value")
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
describe ".from_access_token_param" do
|
|
43
|
+
it "returns token from access_token parameter" do
|
|
44
|
+
request = double parameters: { access_token: "some-token" }
|
|
45
|
+
token = described_class.from_access_token_param(request)
|
|
46
|
+
expect(token).to eq("some-token")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
describe ".from_bearer_param" do
|
|
51
|
+
it "returns token from bearer_token parameter" do
|
|
52
|
+
request = double parameters: { bearer_token: "some-token" }
|
|
53
|
+
token = described_class.from_bearer_param(request)
|
|
54
|
+
expect(token).to eq("some-token")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
describe ".from_bearer_authorization" do
|
|
59
|
+
it "returns token from capitalized authorization bearer" do
|
|
60
|
+
request = double authorization: "Bearer SomeToken"
|
|
61
|
+
token = described_class.from_bearer_authorization(request)
|
|
62
|
+
expect(token).to eq("SomeToken")
|
|
63
|
+
end
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
it "returns token from lowercased authorization bearer" do
|
|
66
|
+
request = double authorization: "bearer SomeToken"
|
|
67
|
+
token = described_class.from_bearer_authorization(request)
|
|
68
|
+
expect(token).to eq("SomeToken")
|
|
69
|
+
end
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
it "does not return token if authorization is not bearer" do
|
|
72
|
+
request = double authorization: "MAC SomeToken"
|
|
73
|
+
token = described_class.from_bearer_authorization(request)
|
|
74
|
+
expect(token).to be_blank
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
describe ".from_basic_authorization" do
|
|
79
|
+
it "returns token from capitalized authorization basic" do
|
|
80
|
+
request = double authorization: "Basic #{Base64.encode64 "SomeToken:"}"
|
|
81
|
+
token = described_class.from_basic_authorization(request)
|
|
82
|
+
expect(token).to eq("SomeToken")
|
|
83
|
+
end
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
it "returns token from lowercased authorization basic" do
|
|
86
|
+
request = double authorization: "basic #{Base64.encode64 "SomeToken:"}"
|
|
87
|
+
token = described_class.from_basic_authorization(request)
|
|
88
|
+
expect(token).to eq("SomeToken")
|
|
89
|
+
end
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
it "does not return token if authorization is not basic" do
|
|
92
|
+
request = double authorization: "MAC #{Base64.encode64 "SomeToken:"}"
|
|
93
|
+
token = described_class.from_basic_authorization(request)
|
|
94
|
+
expect(token).to be_blank
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe ".authenticate" do
|
|
99
|
+
context "refresh tokens are disabled (default)" do
|
|
100
|
+
context "refresh tokens are enabled" do
|
|
101
|
+
it "does not revoke previous refresh_token if token was found" do
|
|
102
|
+
token = ->(_r) { "token" }
|
|
103
|
+
expect(
|
|
104
|
+
Doorkeeper::AccessToken,
|
|
105
|
+
).to receive(:by_token).with("token").and_return(token)
|
|
106
|
+
expect(token).not_to receive(:revoke_previous_refresh_token!)
|
|
107
|
+
described_class.authenticate double, token
|
|
95
108
|
end
|
|
96
109
|
end
|
|
97
110
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
AccessToken
|
|
105
|
-
).to receive(:by_token).with("token").and_return(token)
|
|
106
|
-
expect(token).not_to receive(:revoke_previous_refresh_token!)
|
|
107
|
-
Token.authenticate double, token
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it "calls the finder if token was returned" do
|
|
112
|
-
token = ->(_r) { "token" }
|
|
113
|
-
expect(AccessToken).to receive(:by_token).with("token")
|
|
114
|
-
Token.authenticate double, token
|
|
115
|
-
end
|
|
116
|
-
end
|
|
111
|
+
it "calls the finder if token was returned" do
|
|
112
|
+
token = ->(_r) { "token" }
|
|
113
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with("token")
|
|
114
|
+
described_class.authenticate double, token
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
context "token hashing is enabled" do
|
|
119
|
+
include_context "with token hashing enabled"
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
let(:hashed_token) { hashed_or_plain_token_func.call("token") }
|
|
122
|
+
let(:token) { ->(_r) { "token" } }
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
it "searches with the hashed token" do
|
|
125
|
+
expect(
|
|
126
|
+
Doorkeeper::AccessToken,
|
|
127
|
+
).to receive(:find_by).with(token: hashed_token).and_return(token)
|
|
128
|
+
described_class.authenticate double, token
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it "revokes previous refresh_token if token was found" do
|
|
141
|
-
token = ->(_r) { "token" }
|
|
142
|
-
expect(
|
|
143
|
-
AccessToken
|
|
144
|
-
).to receive(:by_token).with("token").and_return(token)
|
|
145
|
-
expect(token).to receive(:revoke_previous_refresh_token!)
|
|
146
|
-
Token.authenticate double, token
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
it "calls the finder if token was returned" do
|
|
150
|
-
token = ->(_r) { "token" }
|
|
151
|
-
expect(AccessToken).to receive(:by_token).with("token")
|
|
152
|
-
Token.authenticate double, token
|
|
153
|
-
end
|
|
132
|
+
context "refresh tokens are enabled" do
|
|
133
|
+
before do
|
|
134
|
+
Doorkeeper.configure do
|
|
135
|
+
orm DOORKEEPER_ORM
|
|
136
|
+
use_refresh_token
|
|
154
137
|
end
|
|
155
138
|
end
|
|
139
|
+
|
|
140
|
+
it "revokes previous refresh_token if token was found" do
|
|
141
|
+
token = ->(_r) { "token" }
|
|
142
|
+
expect(
|
|
143
|
+
Doorkeeper::AccessToken,
|
|
144
|
+
).to receive(:by_token).with("token").and_return(token)
|
|
145
|
+
expect(token).to receive(:revoke_previous_refresh_token!)
|
|
146
|
+
described_class.authenticate double, token
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "calls the finder if token was returned" do
|
|
150
|
+
token = ->(_r) { "token" }
|
|
151
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with("token")
|
|
152
|
+
described_class.authenticate double, token
|
|
153
|
+
end
|
|
156
154
|
end
|
|
157
155
|
end
|
|
158
156
|
end
|
|
@@ -61,10 +61,27 @@ describe Doorkeeper::AccessGrant do
|
|
|
61
61
|
it "upgrades a plain token when falling back to it" do
|
|
62
62
|
# Side-effect: This will automatically upgrade the token
|
|
63
63
|
expect(clazz).to receive(:upgrade_fallback_value).and_call_original
|
|
64
|
-
expect(clazz.by_token(plain_text_token))
|
|
64
|
+
expect(clazz.by_token(plain_text_token))
|
|
65
|
+
.to have_attributes(
|
|
66
|
+
resource_owner_id: grant.resource_owner_id,
|
|
67
|
+
application_id: grant.application_id,
|
|
68
|
+
redirect_uri: grant.redirect_uri,
|
|
69
|
+
expires_in: grant.expires_in,
|
|
70
|
+
scopes: grant.scopes,
|
|
71
|
+
)
|
|
65
72
|
|
|
66
73
|
# Will find subsequently by hashing the token
|
|
67
|
-
expect(clazz.by_token(plain_text_token))
|
|
74
|
+
expect(clazz.by_token(plain_text_token))
|
|
75
|
+
.to have_attributes(
|
|
76
|
+
resource_owner_id: grant.resource_owner_id,
|
|
77
|
+
application_id: grant.application_id,
|
|
78
|
+
redirect_uri: grant.redirect_uri,
|
|
79
|
+
expires_in: grant.expires_in,
|
|
80
|
+
scopes: grant.scopes,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# Not all the ORM support :id PK
|
|
84
|
+
expect(clazz.by_token(plain_text_token).id).to eq(grant.id) if grant.respond_to?(:id)
|
|
68
85
|
|
|
69
86
|
# And it modifies the token value
|
|
70
87
|
grant.reload
|
|
@@ -122,7 +139,7 @@ describe Doorkeeper::AccessGrant do
|
|
|
122
139
|
it "matches application" do
|
|
123
140
|
access_grant_for_different_app = FactoryBot.create(
|
|
124
141
|
:access_grant,
|
|
125
|
-
default_attributes.merge(application: FactoryBot.create(:application))
|
|
142
|
+
default_attributes.merge(application: FactoryBot.create(:application)),
|
|
126
143
|
)
|
|
127
144
|
|
|
128
145
|
described_class.revoke_all_for(application.id, resource_owner)
|
|
@@ -133,7 +150,7 @@ describe Doorkeeper::AccessGrant do
|
|
|
133
150
|
it "matches resource owner" do
|
|
134
151
|
access_grant_for_different_owner = FactoryBot.create(
|
|
135
152
|
:access_grant,
|
|
136
|
-
default_attributes.merge(resource_owner_id: 90)
|
|
153
|
+
default_attributes.merge(resource_owner_id: 90),
|
|
137
154
|
)
|
|
138
155
|
|
|
139
156
|
described_class.revoke_all_for application.id, resource_owner
|
|
@@ -73,10 +73,25 @@ module Doorkeeper
|
|
|
73
73
|
it "upgrades a plain token when falling back to it" do
|
|
74
74
|
# Side-effect: This will automatically upgrade the token
|
|
75
75
|
expect(clazz).to receive(:upgrade_fallback_value).and_call_original
|
|
76
|
-
expect(clazz.by_token(plain_text_token))
|
|
76
|
+
expect(clazz.by_token(plain_text_token))
|
|
77
|
+
.to have_attributes(
|
|
78
|
+
resource_owner_id: access_token.resource_owner_id,
|
|
79
|
+
application_id: access_token.application_id,
|
|
80
|
+
scopes: access_token.scopes,
|
|
81
|
+
)
|
|
77
82
|
|
|
78
83
|
# Will find subsequently by hashing the token
|
|
79
|
-
expect(clazz.by_token(plain_text_token))
|
|
84
|
+
expect(clazz.by_token(plain_text_token))
|
|
85
|
+
.to have_attributes(
|
|
86
|
+
resource_owner_id: access_token.resource_owner_id,
|
|
87
|
+
application_id: access_token.application_id,
|
|
88
|
+
scopes: access_token.scopes,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Not all the ORM support :id PK
|
|
92
|
+
if access_token.respond_to?(:id)
|
|
93
|
+
expect(clazz.by_token(plain_text_token).id).to eq(access_token.id)
|
|
94
|
+
end
|
|
80
95
|
|
|
81
96
|
# And it modifies the token value
|
|
82
97
|
access_token.reload
|
|
@@ -113,6 +128,7 @@ module Doorkeeper
|
|
|
113
128
|
eigenclass.class_eval do
|
|
114
129
|
remove_method :generate
|
|
115
130
|
end
|
|
131
|
+
|
|
116
132
|
module CustomGeneratorArgs
|
|
117
133
|
def self.generate(opts = {})
|
|
118
134
|
"custom_generator_token_#{opts[:application].name}"
|
|
@@ -196,7 +212,7 @@ module Doorkeeper
|
|
|
196
212
|
end
|
|
197
213
|
|
|
198
214
|
expect { FactoryBot.create :access_token }.to(
|
|
199
|
-
raise_error(Doorkeeper::Errors::UnableToGenerateToken)
|
|
215
|
+
raise_error(Doorkeeper::Errors::UnableToGenerateToken),
|
|
200
216
|
)
|
|
201
217
|
end
|
|
202
218
|
|
|
@@ -218,7 +234,7 @@ module Doorkeeper
|
|
|
218
234
|
end
|
|
219
235
|
|
|
220
236
|
expect { FactoryBot.create :access_token }.to(
|
|
221
|
-
raise_error(LoadError)
|
|
237
|
+
raise_error(LoadError),
|
|
222
238
|
)
|
|
223
239
|
end
|
|
224
240
|
|
|
@@ -229,7 +245,7 @@ module Doorkeeper
|
|
|
229
245
|
end
|
|
230
246
|
|
|
231
247
|
expect { FactoryBot.create :access_token }.to(
|
|
232
|
-
raise_error(Doorkeeper::Errors::TokenGeneratorNotFound, /NotReal/)
|
|
248
|
+
raise_error(Doorkeeper::Errors::TokenGeneratorNotFound, /NotReal/),
|
|
233
249
|
)
|
|
234
250
|
end
|
|
235
251
|
end
|
|
@@ -307,10 +323,25 @@ module Doorkeeper
|
|
|
307
323
|
it "upgrades a plain token when falling back to it" do
|
|
308
324
|
# Side-effect: This will automatically upgrade the token
|
|
309
325
|
expect(clazz).to receive(:upgrade_fallback_value).and_call_original
|
|
310
|
-
expect(clazz.by_refresh_token(plain_refresh_token))
|
|
326
|
+
expect(clazz.by_refresh_token(plain_refresh_token))
|
|
327
|
+
.to have_attributes(
|
|
328
|
+
token: access_token.token,
|
|
329
|
+
resource_owner_id: access_token.resource_owner_id,
|
|
330
|
+
application_id: access_token.application_id,
|
|
331
|
+
)
|
|
311
332
|
|
|
312
333
|
# Will find subsequently by hashing the token
|
|
313
|
-
expect(clazz.by_refresh_token(plain_refresh_token))
|
|
334
|
+
expect(clazz.by_refresh_token(plain_refresh_token))
|
|
335
|
+
.to have_attributes(
|
|
336
|
+
token: access_token.token,
|
|
337
|
+
resource_owner_id: access_token.resource_owner_id,
|
|
338
|
+
application_id: access_token.application_id,
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
# Not all the ORM support :id PK
|
|
342
|
+
if access_token.respond_to?(:id)
|
|
343
|
+
expect(clazz.by_refresh_token(plain_refresh_token).id).to eq(access_token.id)
|
|
344
|
+
end
|
|
314
345
|
|
|
315
346
|
# And it modifies the token value
|
|
316
347
|
access_token.reload
|
|
@@ -437,7 +468,7 @@ module Doorkeeper
|
|
|
437
468
|
it "matches application" do
|
|
438
469
|
access_token_for_different_app = FactoryBot.create(
|
|
439
470
|
:access_token,
|
|
440
|
-
default_attributes.merge(application: FactoryBot.create(:application))
|
|
471
|
+
default_attributes.merge(application: FactoryBot.create(:application)),
|
|
441
472
|
)
|
|
442
473
|
|
|
443
474
|
AccessToken.revoke_all_for application.id, resource_owner
|
|
@@ -448,7 +479,7 @@ module Doorkeeper
|
|
|
448
479
|
it "matches resource owner" do
|
|
449
480
|
access_token_for_different_owner = FactoryBot.create(
|
|
450
481
|
:access_token,
|
|
451
|
-
default_attributes.merge(resource_owner_id: 90)
|
|
482
|
+
default_attributes.merge(resource_owner_id: 90),
|
|
452
483
|
)
|
|
453
484
|
|
|
454
485
|
AccessToken.revoke_all_for application.id, resource_owner
|
|
@@ -530,7 +561,7 @@ module Doorkeeper
|
|
|
530
561
|
|
|
531
562
|
it "excludes tokens with scopes that are not present in server scopes" do
|
|
532
563
|
FactoryBot.create :access_token, default_attributes.merge(
|
|
533
|
-
application: application, scopes: "public read"
|
|
564
|
+
application: application, scopes: "public read",
|
|
534
565
|
)
|
|
535
566
|
last_token = AccessToken.matching_token_for(application, resource_owner_id, scopes)
|
|
536
567
|
expect(last_token).to be_nil
|
|
@@ -539,7 +570,7 @@ module Doorkeeper
|
|
|
539
570
|
it "excludes tokens with scopes that are not present in application scopes" do
|
|
540
571
|
application = FactoryBot.create :application, scopes: "private read"
|
|
541
572
|
FactoryBot.create :access_token, default_attributes.merge(
|
|
542
|
-
application: application
|
|
573
|
+
application: application,
|
|
543
574
|
)
|
|
544
575
|
last_token = AccessToken.matching_token_for(application, resource_owner_id, scopes)
|
|
545
576
|
expect(last_token).to be_nil
|