doorkeeper 4.0.0.rc2 → 4.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of doorkeeper might be problematic. Click here for more details.

Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/Gemfile +0 -4
  4. data/NEWS.md +20 -1
  5. data/README.md +23 -25
  6. data/app/views/doorkeeper/applications/show.html.erb +1 -1
  7. data/doorkeeper.gemspec +4 -3
  8. data/lib/doorkeeper/config.rb +16 -4
  9. data/lib/doorkeeper/engine.rb +2 -7
  10. data/lib/doorkeeper/models/access_grant_mixin.rb +0 -4
  11. data/lib/doorkeeper/models/access_token_mixin.rb +1 -5
  12. data/lib/doorkeeper/models/application_mixin.rb +0 -4
  13. data/lib/doorkeeper/models/concerns/expirable.rb +2 -2
  14. data/lib/doorkeeper/models/concerns/revocable.rb +19 -2
  15. data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
  16. data/lib/doorkeeper/oauth/client_credentials_request.rb +3 -1
  17. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
  18. data/lib/doorkeeper/oauth/refresh_token_request.rb +23 -11
  19. data/lib/doorkeeper/oauth/token.rb +3 -1
  20. data/lib/doorkeeper/version.rb +1 -1
  21. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -0
  22. data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb +11 -0
  23. data/lib/generators/doorkeeper/templates/initializer.rb +2 -2
  24. data/lib/generators/doorkeeper/templates/migration.rb +10 -2
  25. data/spec/controllers/protected_resources_controller_spec.rb +35 -6
  26. data/spec/dummy/app/models/user.rb +0 -4
  27. data/spec/dummy/config/initializers/doorkeeper.rb +2 -2
  28. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +11 -0
  29. data/spec/dummy/db/schema.rb +4 -3
  30. data/spec/lib/config_spec.rb +1 -1
  31. data/spec/lib/models/revocable_spec.rb +27 -4
  32. data/spec/lib/oauth/refresh_token_request_spec.rb +30 -5
  33. data/spec/lib/oauth/scopes_spec.rb +0 -1
  34. data/spec/lib/oauth/token_spec.rb +12 -5
  35. data/spec/models/doorkeeper/access_token_spec.rb +22 -1
  36. data/spec/models/doorkeeper/application_spec.rb +1 -1
  37. data/spec/requests/flows/refresh_token_spec.rb +87 -17
  38. data/spec/support/shared/controllers_shared_context.rb +13 -4
  39. metadata +40 -22
@@ -12,6 +12,11 @@ module Doorkeeper
12
12
  let(:factory_name) { :access_token }
13
13
  end
14
14
 
15
+ module CustomGeneratorArgs
16
+ def self.generate
17
+ end
18
+ end
19
+
15
20
  describe :generate_token do
16
21
  it 'generates a token using the default method' do
17
22
  FactoryGirl.create :access_token
@@ -21,6 +26,10 @@ module Doorkeeper
21
26
  end
22
27
 
23
28
  it 'generates a token using a custom object' do
29
+ eigenclass = class << CustomGeneratorArgs; self; end
30
+ eigenclass.class_eval do
31
+ remove_method :generate
32
+ end
24
33
  module CustomGeneratorArgs
25
34
  def self.generate(opts = {})
26
35
  "custom_generator_token_#{opts[:resource_owner_id]}"
@@ -37,6 +46,10 @@ module Doorkeeper
37
46
  end
38
47
 
39
48
  it 'allows the custom generator to access the application details' do
49
+ eigenclass = class << CustomGeneratorArgs; self; end
50
+ eigenclass.class_eval do
51
+ remove_method :generate
52
+ end
40
53
  module CustomGeneratorArgs
41
54
  def self.generate(opts = {})
42
55
  "custom_generator_token_#{opts[:application].name}"
@@ -53,6 +66,10 @@ module Doorkeeper
53
66
  end
54
67
 
55
68
  it 'allows the custom generator to access the scopes' do
69
+ eigenclass = class << CustomGeneratorArgs; self; end
70
+ eigenclass.class_eval do
71
+ remove_method :generate
72
+ end
56
73
  module CustomGeneratorArgs
57
74
  def self.generate(opts = {})
58
75
  "custom_generator_token_#{opts[:scopes].count}_#{opts[:scopes]}"
@@ -70,6 +87,10 @@ module Doorkeeper
70
87
  end
71
88
 
72
89
  it 'allows the custom generator to access the expiry length' do
90
+ eigenclass = class << CustomGeneratorArgs; self; end
91
+ eigenclass.class_eval do
92
+ remove_method :generate
93
+ end
73
94
  module CustomGeneratorArgs
74
95
  def self.generate(opts = {})
75
96
  "custom_generator_token_#{opts[:expires_in]}"
@@ -144,7 +165,7 @@ module Doorkeeper
144
165
  expect(subject).to be_valid
145
166
  end
146
167
 
147
- it 'is valid without resource_owner_id' do
168
+ it 'is valid without application_id' do
148
169
  # For resource owner credentials flow
149
170
  subject.application_id = nil
150
171
  expect(subject).to be_valid
@@ -129,7 +129,7 @@ module Doorkeeper
129
129
 
130
130
  it 'should destroy its access tokens' do
131
131
  FactoryGirl.create(:access_token, application: new_application)
132
- FactoryGirl.create(:access_token, application: new_application, revoked_at: Time.now)
132
+ FactoryGirl.create(:access_token, application: new_application, revoked_at: Time.now.utc)
133
133
  expect do
134
134
  new_application.destroy
135
135
  end.to change { Doorkeeper::AccessToken.count }.by(-2)
@@ -37,20 +37,62 @@ describe 'Refresh Token Flow' do
37
37
 
38
38
  context 'refreshing the token' do
39
39
  before do
40
- @token = FactoryGirl.create(:access_token, application: @client, resource_owner_id: 1, use_refresh_token: true)
40
+ @token = FactoryGirl.create(
41
+ :access_token,
42
+ application: @client,
43
+ resource_owner_id: 1,
44
+ use_refresh_token: true
45
+ )
41
46
  end
42
47
 
43
- it 'client request a token with refresh token' do
44
- post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
45
- should_have_json 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
46
- expect(@token.reload).to be_revoked
48
+ context "refresh_token revoked on use" do
49
+ it 'client request a token with refresh token' do
50
+ post refresh_token_endpoint_url(
51
+ client: @client, refresh_token: @token.refresh_token
52
+ )
53
+ should_have_json(
54
+ 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
55
+ )
56
+ expect(@token.reload).not_to be_revoked
57
+ end
58
+
59
+ it 'client request a token with expired access token' do
60
+ @token.update_attribute :expires_in, -100
61
+ post refresh_token_endpoint_url(
62
+ client: @client, refresh_token: @token.refresh_token
63
+ )
64
+ should_have_json(
65
+ 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
66
+ )
67
+ expect(@token.reload).not_to be_revoked
68
+ end
47
69
  end
48
70
 
49
- it 'client request a token with expired access token' do
50
- @token.update_attribute :expires_in, -100
51
- post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
52
- should_have_json 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
53
- expect(@token.reload).to be_revoked
71
+ context "refresh_token revoked on refresh_token request" do
72
+ before do
73
+ config_is_set(:refresh_token_revoked_on_use, false)
74
+ end
75
+
76
+ it 'client request a token with refresh token' do
77
+ post refresh_token_endpoint_url(
78
+ client: @client, refresh_token: @token.refresh_token
79
+ )
80
+ should_have_json(
81
+ 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
82
+ )
83
+ expect(@token.reload).to be_revoked
84
+ end
85
+
86
+ it 'client request a token with expired access token' do
87
+ @token.update_attribute :expires_in, -100
88
+ post refresh_token_endpoint_url(
89
+ client: @client, refresh_token: @token.refresh_token
90
+ )
91
+ should_have_json(
92
+ 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
93
+ )
94
+ expect(@token.reload).to be_revoked
95
+ end
54
96
  end
55
97
 
56
98
  it 'client gets an error for invalid refresh token' do
@@ -79,20 +121,48 @@ describe 'Refresh Token Flow' do
79
121
  before do
80
122
  # enable password auth to simulate other devices
81
123
  config_is_set(:grant_flows, ["password"])
82
- config_is_set(:resource_owner_from_credentials) { User.authenticate! params[:username], params[:password] }
124
+ config_is_set(:resource_owner_from_credentials) do
125
+ User.authenticate! params[:username], params[:password]
126
+ end
83
127
  create_resource_owner
84
- _another_token = post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
128
+ _another_token = post password_token_endpoint_url(
129
+ client: @client, resource_owner: @resource_owner
130
+ )
85
131
  last_token.update_attribute :created_at, 5.seconds.ago
86
132
 
87
- @token = FactoryGirl.create(:access_token, application: @client, resource_owner_id: @resource_owner.id, use_refresh_token: true)
133
+ @token = FactoryGirl.create(
134
+ :access_token,
135
+ application: @client,
136
+ resource_owner_id: @resource_owner.id,
137
+ use_refresh_token: true
138
+ )
88
139
  @token.update_attribute :expires_in, -100
89
140
  end
90
141
 
91
- it 'client request a token after creating another token with the same user' do
92
- post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
142
+ context "refresh_token revoked on use" do
143
+ it 'client request a token after creating another token with the same user' do
144
+ post refresh_token_endpoint_url(
145
+ client: @client, refresh_token: @token.refresh_token
146
+ )
147
+
148
+ should_have_json 'refresh_token', last_token.refresh_token
149
+ expect(@token.reload).not_to be_revoked
150
+ end
151
+ end
152
+
153
+ context "refresh_token revoked on refresh_token request" do
154
+ before do
155
+ config_is_set(:refresh_token_revoked_on_use, false)
156
+ end
157
+
158
+ it 'client request a token after creating another token with the same user' do
159
+ post refresh_token_endpoint_url(
160
+ client: @client, refresh_token: @token.refresh_token
161
+ )
93
162
 
94
- should_have_json 'refresh_token', last_token.refresh_token
95
- expect(@token.reload).to be_revoked
163
+ should_have_json 'refresh_token', last_token.refresh_token
164
+ expect(@token.reload).to be_revoked
165
+ end
96
166
  end
97
167
 
98
168
  def last_token
@@ -4,11 +4,15 @@ shared_context 'valid token', token: :valid do
4
4
  end
5
5
 
6
6
  let :token do
7
- double(Doorkeeper::AccessToken, accessible?: true, includes_scope?: true, acceptable?: true)
7
+ double(Doorkeeper::AccessToken,
8
+ accessible?: true, includes_scope?: true, acceptable?: true,
9
+ previous_refresh_token: "", revoke_previous_refresh_token!: true)
8
10
  end
9
11
 
10
12
  before :each do
11
- allow(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
13
+ allow(
14
+ Doorkeeper::AccessToken
15
+ ).to receive(:by_token).with(token_string).and_return(token)
12
16
  end
13
17
  end
14
18
 
@@ -18,11 +22,16 @@ shared_context 'invalid token', token: :invalid do
18
22
  end
19
23
 
20
24
  let :token do
21
- double(Doorkeeper::AccessToken, accessible?: false, revoked?: false, expired?: false, includes_scope?: false, acceptable?: false)
25
+ double(Doorkeeper::AccessToken,
26
+ accessible?: false, revoked?: false, expired?: false,
27
+ includes_scope?: false, acceptable?: false,
28
+ previous_refresh_token: "", revoke_previous_refresh_token!: true)
22
29
  end
23
30
 
24
31
  before :each do
25
- allow(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
32
+ allow(
33
+ Doorkeeper::AccessToken
34
+ ).to receive(:by_token).with(token_string).and_return(token)
26
35
  end
27
36
  end
28
37
 
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: 4.0.0.rc2
4
+ version: 4.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Elias Philipp
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-03 00:00:00.000000000 Z
12
+ date: 2016-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -26,7 +26,7 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '4.2'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rspec-rails
29
+ name: capybara
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
@@ -40,19 +40,33 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: capybara
43
+ name: database_cleaner
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: 1.3.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: 1.3.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: factory_girl
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 4.5.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 4.5.0
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: generator_spec
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -68,47 +82,47 @@ dependencies:
68
82
  - !ruby/object:Gem::Version
69
83
  version: 0.9.0
70
84
  - !ruby/object:Gem::Dependency
71
- name: factory_girl
85
+ name: rake
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
- - - "~>"
88
+ - - ">"
75
89
  - !ruby/object:Gem::Version
76
- version: 4.5.0
90
+ version: 10.5.0
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
- - - "~>"
95
+ - - ">"
82
96
  - !ruby/object:Gem::Version
83
- version: 4.5.0
97
+ version: 10.5.0
84
98
  - !ruby/object:Gem::Dependency
85
- name: timecop
99
+ name: rspec-rails
86
100
  requirement: !ruby/object:Gem::Requirement
87
101
  requirements:
88
- - - "~>"
102
+ - - ">="
89
103
  - !ruby/object:Gem::Version
90
- version: 0.7.0
104
+ version: '0'
91
105
  type: :development
92
106
  prerelease: false
93
107
  version_requirements: !ruby/object:Gem::Requirement
94
108
  requirements:
95
- - - "~>"
109
+ - - ">="
96
110
  - !ruby/object:Gem::Version
97
- version: 0.7.0
111
+ version: '0'
98
112
  - !ruby/object:Gem::Dependency
99
- name: database_cleaner
113
+ name: timecop
100
114
  requirement: !ruby/object:Gem::Requirement
101
115
  requirements:
102
116
  - - "~>"
103
117
  - !ruby/object:Gem::Version
104
- version: 1.3.0
118
+ version: 0.7.0
105
119
  type: :development
106
120
  prerelease: false
107
121
  version_requirements: !ruby/object:Gem::Requirement
108
122
  requirements:
109
123
  - - "~>"
110
124
  - !ruby/object:Gem::Version
111
- version: 1.3.0
125
+ version: 0.7.0
112
126
  description: Doorkeeper is an OAuth 2 provider for Rails and Grape.
113
127
  email:
114
128
  - tutecosta@gmail.com
@@ -219,8 +233,10 @@ files:
219
233
  - lib/generators/doorkeeper/application_scopes_generator.rb
220
234
  - lib/generators/doorkeeper/install_generator.rb
221
235
  - lib/generators/doorkeeper/migration_generator.rb
236
+ - lib/generators/doorkeeper/previous_refresh_token_generator.rb
222
237
  - lib/generators/doorkeeper/templates/README
223
238
  - lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb
239
+ - lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb
224
240
  - lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb
225
241
  - lib/generators/doorkeeper/templates/initializer.rb
226
242
  - lib/generators/doorkeeper/templates/migration.rb
@@ -261,6 +277,7 @@ files:
261
277
  - spec/dummy/db/migrate/20120312140401_add_password_to_users.rb
262
278
  - spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb
263
279
  - spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb
280
+ - spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb
264
281
  - spec/dummy/db/schema.rb
265
282
  - spec/dummy/public/404.html
266
283
  - spec/dummy/public/422.html
@@ -362,7 +379,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
362
379
  version: 1.3.1
363
380
  requirements: []
364
381
  rubyforge_project:
365
- rubygems_version: 2.5.1
382
+ rubygems_version: 2.6.2
366
383
  signing_key:
367
384
  specification_version: 4
368
385
  summary: OAuth 2 provider for Rails and Grape
@@ -403,6 +420,7 @@ test_files:
403
420
  - spec/dummy/db/migrate/20120312140401_add_password_to_users.rb
404
421
  - spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb
405
422
  - spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb
423
+ - spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb
406
424
  - spec/dummy/db/schema.rb
407
425
  - spec/dummy/public/404.html
408
426
  - spec/dummy/public/422.html