doorkeeper 3.1.0 → 4.2.6

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 (137) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +5 -0
  4. data/.travis.yml +16 -12
  5. data/Appraisals +14 -0
  6. data/CONTRIBUTING.md +2 -0
  7. data/Gemfile +5 -5
  8. data/NEWS.md +83 -2
  9. data/README.md +73 -43
  10. data/RELEASING.md +5 -12
  11. data/Rakefile +1 -1
  12. data/app/controllers/doorkeeper/application_controller.rb +3 -1
  13. data/app/controllers/doorkeeper/application_metal_controller.rb +3 -2
  14. data/app/controllers/doorkeeper/applications_controller.rb +3 -7
  15. data/app/controllers/doorkeeper/authorizations_controller.rb +1 -1
  16. data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
  17. data/app/controllers/doorkeeper/tokens_controller.rb +50 -14
  18. data/app/helpers/doorkeeper/dashboard_helper.rb +13 -11
  19. data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -2
  20. data/app/views/doorkeeper/applications/_form.html.erb +1 -1
  21. data/app/views/doorkeeper/applications/show.html.erb +1 -1
  22. data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
  23. data/app/views/doorkeeper/authorized_applications/_delete_form.html.erb +1 -2
  24. data/app/views/layouts/doorkeeper/admin.html.erb +1 -1
  25. data/config/locales/en.yml +3 -2
  26. data/doorkeeper.gemspec +12 -10
  27. data/gemfiles/rails_4_2.gemfile +11 -0
  28. data/gemfiles/rails_5_0.gemfile +12 -0
  29. data/gemfiles/rails_5_1.gemfile +13 -0
  30. data/lib/doorkeeper/config.rb +73 -16
  31. data/lib/doorkeeper/engine.rb +11 -7
  32. data/lib/doorkeeper/errors.rb +18 -0
  33. data/lib/doorkeeper/grape/helpers.rb +2 -1
  34. data/lib/doorkeeper/helpers/controller.rb +8 -23
  35. data/lib/doorkeeper/models/access_grant_mixin.rb +21 -5
  36. data/lib/doorkeeper/models/access_token_mixin.rb +145 -23
  37. data/lib/doorkeeper/models/application_mixin.rb +21 -9
  38. data/lib/doorkeeper/models/concerns/accessible.rb +4 -0
  39. data/lib/doorkeeper/models/concerns/expirable.rb +10 -2
  40. data/lib/doorkeeper/models/concerns/ownership.rb +6 -1
  41. data/lib/doorkeeper/models/concerns/revocable.rb +37 -2
  42. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +20 -18
  43. data/lib/doorkeeper/oauth/authorization_code_request.rb +1 -4
  44. data/lib/doorkeeper/oauth/{request_concern.rb → base_request.rb} +3 -1
  45. data/lib/doorkeeper/oauth/base_response.rb +29 -0
  46. data/lib/doorkeeper/oauth/client/credentials.rb +17 -6
  47. data/lib/doorkeeper/oauth/client.rb +0 -1
  48. data/lib/doorkeeper/oauth/client_credentials/creator.rb +1 -1
  49. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +3 -2
  50. data/lib/doorkeeper/oauth/client_credentials/validation.rb +1 -1
  51. data/lib/doorkeeper/oauth/client_credentials_request.rb +8 -8
  52. data/lib/doorkeeper/oauth/code_response.rb +16 -16
  53. data/lib/doorkeeper/oauth/error_response.rb +9 -8
  54. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
  55. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +2 -1
  56. data/lib/doorkeeper/oauth/invalid_token_response.rb +2 -0
  57. data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -13
  58. data/lib/doorkeeper/oauth/refresh_token_request.rb +22 -14
  59. data/lib/doorkeeper/oauth/scopes.rb +2 -2
  60. data/lib/doorkeeper/oauth/token.rb +20 -21
  61. data/lib/doorkeeper/oauth/token_request.rb +1 -2
  62. data/lib/doorkeeper/oauth/token_response.rb +1 -1
  63. data/lib/doorkeeper/orm/active_record/access_token.rb +25 -0
  64. data/lib/doorkeeper/orm/active_record/application.rb +12 -12
  65. data/lib/doorkeeper/orm/active_record.rb +0 -16
  66. data/lib/doorkeeper/rails/helpers.rb +1 -3
  67. data/lib/doorkeeper/rails/routes/mapper.rb +4 -4
  68. data/lib/doorkeeper/rails/routes/mapping.rb +1 -1
  69. data/lib/doorkeeper/rails/routes.rb +4 -4
  70. data/lib/doorkeeper/request/authorization_code.rb +7 -1
  71. data/lib/doorkeeper/request/password.rb +11 -1
  72. data/lib/doorkeeper/request/refresh_token.rb +1 -1
  73. data/lib/doorkeeper/server.rb +0 -8
  74. data/lib/doorkeeper/version.rb +1 -1
  75. data/lib/doorkeeper.rb +8 -2
  76. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -0
  77. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +1 -1
  78. data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb +11 -0
  79. data/lib/generators/doorkeeper/templates/initializer.rb +8 -3
  80. data/lib/generators/doorkeeper/templates/migration.rb +23 -5
  81. data/spec/controllers/application_metal_controller.rb +10 -0
  82. data/spec/controllers/authorizations_controller_spec.rb +39 -24
  83. data/spec/controllers/protected_resources_controller_spec.rb +47 -18
  84. data/spec/controllers/tokens_controller_spec.rb +1 -1
  85. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -4
  86. data/spec/dummy/app/controllers/home_controller.rb +1 -1
  87. data/spec/dummy/app/controllers/metal_controller.rb +1 -1
  88. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +3 -3
  89. data/spec/dummy/app/models/user.rb +0 -4
  90. data/spec/dummy/config/application.rb +2 -36
  91. data/spec/dummy/config/environment.rb +1 -1
  92. data/spec/dummy/config/environments/test.rb +4 -15
  93. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +6 -0
  94. data/spec/dummy/config/initializers/doorkeeper.rb +2 -2
  95. data/spec/dummy/db/migrate/{20130902165751_create_doorkeeper_tables.rb → 20151223192035_create_doorkeeper_tables.rb} +24 -5
  96. data/spec/dummy/db/migrate/{20130902175349_add_owner_to_application.rb → 20151223200000_add_owner_to_application.rb} +0 -0
  97. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +11 -0
  98. data/spec/dummy/db/schema.rb +23 -22
  99. data/spec/factories.rb +3 -1
  100. data/spec/lib/config_spec.rb +19 -2
  101. data/spec/lib/doorkeeper_spec.rb +135 -13
  102. data/spec/lib/models/expirable_spec.rb +0 -1
  103. data/spec/lib/models/revocable_spec.rb +27 -4
  104. data/spec/lib/oauth/authorization/uri_builder_spec.rb +1 -2
  105. data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
  106. data/spec/lib/oauth/base_request_spec.rb +160 -0
  107. data/spec/lib/oauth/base_response_spec.rb +45 -0
  108. data/spec/lib/oauth/client/credentials_spec.rb +41 -0
  109. data/spec/lib/oauth/code_response_spec.rb +34 -0
  110. data/spec/lib/oauth/error_response_spec.rb +9 -9
  111. data/spec/lib/oauth/invalid_token_response_spec.rb +36 -8
  112. data/spec/lib/oauth/password_access_token_request_spec.rb +5 -5
  113. data/spec/lib/oauth/refresh_token_request_spec.rb +34 -3
  114. data/spec/lib/oauth/scopes_spec.rb +0 -1
  115. data/spec/lib/oauth/token_spec.rb +12 -5
  116. data/spec/lib/server_spec.rb +0 -3
  117. data/spec/models/doorkeeper/access_token_spec.rb +45 -1
  118. data/spec/models/doorkeeper/application_spec.rb +3 -11
  119. data/spec/requests/endpoints/authorization_spec.rb +5 -6
  120. data/spec/requests/flows/authorization_code_errors_spec.rb +11 -1
  121. data/spec/requests/flows/authorization_code_spec.rb +4 -12
  122. data/spec/requests/flows/password_spec.rb +26 -5
  123. data/spec/requests/flows/refresh_token_spec.rb +87 -17
  124. data/spec/requests/flows/revoke_token_spec.rb +100 -86
  125. data/spec/spec_helper.rb +2 -0
  126. data/spec/spec_helper_integration.rb +8 -1
  127. data/spec/support/helpers/model_helper.rb +27 -5
  128. data/spec/support/helpers/request_spec_helper.rb +12 -4
  129. data/spec/support/http_method_shim.rb +38 -0
  130. data/spec/support/shared/controllers_shared_context.rb +13 -4
  131. data/spec/support/shared/models_shared_examples.rb +1 -1
  132. metadata +72 -42
  133. data/lib/doorkeeper/oauth/client/methods.rb +0 -18
  134. data/lib/generators/doorkeeper/application_scopes_generator.rb +0 -34
  135. data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +0 -5
  136. data/spec/dummy/db/migrate/20141209001746_add_scopes_to_oauth_applications.rb +0 -5
  137. data/spec/lib/oauth/client/methods_spec.rb +0 -54
@@ -6,14 +6,14 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
6
6
  t.string :secret, null: false
7
7
  t.text :redirect_uri, null: false
8
8
  t.string :scopes, null: false, default: ''
9
- t.timestamps
9
+ t.timestamps null: false
10
10
  end
11
11
 
12
12
  add_index :oauth_applications, :uid, unique: true
13
13
 
14
14
  create_table :oauth_access_grants do |t|
15
15
  t.integer :resource_owner_id, null: false
16
- t.integer :application_id, null: false
16
+ t.references :application, null: false
17
17
  t.string :token, null: false
18
18
  t.integer :expires_in, null: false
19
19
  t.text :redirect_uri, null: false
@@ -23,10 +23,15 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
23
23
  end
24
24
 
25
25
  add_index :oauth_access_grants, :token, unique: true
26
+ add_foreign_key(
27
+ :oauth_access_grants,
28
+ :oauth_applications,
29
+ column: :application_id
30
+ )
26
31
 
27
32
  create_table :oauth_access_tokens do |t|
28
33
  t.integer :resource_owner_id
29
- t.integer :application_id
34
+ t.references :application
30
35
 
31
36
  # If you use a custom token generator you may need to change this column
32
37
  # from string to text, so that it accepts tokens larger than 255
@@ -34,17 +39,30 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
34
39
  # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
35
40
  #
36
41
  # t.text :token, null: false
37
- t.string :token, null: false
42
+ t.string :token, null: false
38
43
 
39
44
  t.string :refresh_token
40
45
  t.integer :expires_in
41
46
  t.datetime :revoked_at
42
- t.datetime :created_at, null: false
47
+ t.datetime :created_at, null: false
43
48
  t.string :scopes
49
+
50
+ # If there is a previous_refresh_token column,
51
+ # refresh tokens will be revoked after a related access token is used.
52
+ # If there is no previous_refresh_token column,
53
+ # previous tokens are revoked as soon as a new access token is created.
54
+ # Comment out this line if you'd rather have refresh tokens
55
+ # instantly revoked.
56
+ t.string :previous_refresh_token, null: false, default: ""
44
57
  end
45
58
 
46
59
  add_index :oauth_access_tokens, :token, unique: true
47
60
  add_index :oauth_access_tokens, :resource_owner_id
48
61
  add_index :oauth_access_tokens, :refresh_token, unique: true
62
+ add_foreign_key(
63
+ :oauth_access_tokens,
64
+ :oauth_applications,
65
+ column: :application_id
66
+ )
49
67
  end
50
68
  end
@@ -0,0 +1,10 @@
1
+ require "spec_helper_integration"
2
+
3
+ describe Doorkeeper::ApplicationMetalController do
4
+ it "lazy run hooks" do
5
+ i = 0
6
+ ActiveSupport.on_load(:doorkeeper_metal_controller) { i += 1 }
7
+
8
+ expect(i).to eq 1
9
+ end
10
+ end
@@ -3,17 +3,33 @@ require 'spec_helper_integration'
3
3
  describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
4
4
  include AuthorizationRequestHelper
5
5
 
6
- def fragments(param)
7
- fragment = URI.parse(response.location).fragment
8
- Rack::Utils.parse_query(fragment)[param]
6
+ if Rails::VERSION::MAJOR == 5
7
+ class ActionDispatch::TestResponse
8
+ def query_params
9
+ @_query_params ||= begin
10
+ fragment = URI.parse(location).fragment
11
+ Rack::Utils.parse_query(fragment)
12
+ end
13
+ end
14
+ end
15
+ else
16
+ class ActionController::TestResponse
17
+ def query_params
18
+ @_query_params ||= begin
19
+ fragment = URI.parse(location).fragment
20
+ Rack::Utils.parse_query(fragment)
21
+ end
22
+ end
23
+ end
9
24
  end
10
25
 
11
26
  def translated_error_message(key)
12
27
  I18n.translate key, scope: [:doorkeeper, :errors, :messages]
13
28
  end
14
29
 
15
- let(:client) { FactoryGirl.create :application }
16
- let(:user) { User.create!(name: 'Joe', password: 'sekret') }
30
+ let(:client) { FactoryGirl.create :application }
31
+ let(:user) { User.create!(name: 'Joe', password: 'sekret') }
32
+ let(:access_token) { FactoryGirl.build :access_token, resource_owner_id: user.id, application_id: client.id }
17
33
 
18
34
  before do
19
35
  allow(Doorkeeper.configuration).to receive(:grant_flows).and_return(["implicit"])
@@ -34,15 +50,15 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
34
50
  end
35
51
 
36
52
  it 'includes access token in fragment' do
37
- expect(fragments('access_token')).to eq(Doorkeeper::AccessToken.first.token)
53
+ expect(response.query_params['access_token']).to eq(Doorkeeper::AccessToken.first.token)
38
54
  end
39
55
 
40
56
  it 'includes token type in fragment' do
41
- expect(fragments('token_type')).to eq('bearer')
57
+ expect(response.query_params['token_type']).to eq('bearer')
42
58
  end
43
59
 
44
60
  it 'includes token expiration in fragment' do
45
- expect(fragments('expires_in').to_i).to eq(2.hours.to_i)
61
+ expect(response.query_params['expires_in'].to_i).to eq(2.hours.to_i)
46
62
  end
47
63
 
48
64
  it 'issues the token for the current client' do
@@ -69,15 +85,15 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
69
85
  end
70
86
 
71
87
  it 'does not include access token in fragment' do
72
- expect(fragments('access_token')).to be_nil
88
+ expect(response.query_params['access_token']).to be_nil
73
89
  end
74
90
 
75
91
  it 'includes error in fragment' do
76
- expect(fragments('error')).to eq('invalid_scope')
92
+ expect(response.query_params['error']).to eq('invalid_scope')
77
93
  end
78
94
 
79
95
  it 'includes error description in fragment' do
80
- expect(fragments('error_description')).to eq(translated_error_message(:invalid_scope))
96
+ expect(response.query_params['error_description']).to eq(translated_error_message(:invalid_scope))
81
97
  end
82
98
 
83
99
  it 'does not issue any access token' do
@@ -86,16 +102,19 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
86
102
  end
87
103
 
88
104
  describe 'POST #create with application already authorized' do
89
- it 'returns the existing access token in a fragment'
90
- end
91
-
92
- describe 'GET #new' do
93
105
  before do
94
- get :new, client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri
106
+ allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
107
+
108
+ access_token.save!
109
+ post :create, client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri
110
+ end
111
+
112
+ it 'returns the existing access token in a fragment' do
113
+ expect(response.query_params['access_token']).to eq(access_token.token)
95
114
  end
96
115
 
97
- it 'renders new template' do
98
- expect(response).to render_template(:new)
116
+ it 'does not creates a new access token' do
117
+ expect(Doorkeeper::AccessToken.count).to eq(1)
99
118
  end
100
119
  end
101
120
 
@@ -165,11 +184,11 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
165
184
  end
166
185
 
167
186
  it 'includes token type in fragment' do
168
- expect(fragments('token_type')).to eq('bearer')
187
+ expect(response.query_params['token_type']).to eq('bearer')
169
188
  end
170
189
 
171
190
  it 'includes token expiration in fragment' do
172
- expect(fragments('expires_in').to_i).to eq(2.hours.to_i)
191
+ expect(response.query_params['expires_in'].to_i).to eq(2.hours.to_i)
173
192
  end
174
193
 
175
194
  it 'issues the token for the current client' do
@@ -191,10 +210,6 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
191
210
  expect(response).to_not be_redirect
192
211
  end
193
212
 
194
- it 'renders error template' do
195
- expect(response).to render_template(:error)
196
- end
197
-
198
213
  it 'does not issue any token' do
199
214
  expect(Doorkeeper::AccessGrant.count).to eq 0
200
215
  expect(Doorkeeper::AccessToken.count).to eq 0
@@ -2,27 +2,35 @@ require 'spec_helper_integration'
2
2
 
3
3
  module ControllerActions
4
4
  def index
5
- render text: 'index'
5
+ render plain: 'index'
6
6
  end
7
7
 
8
8
  def show
9
- render text: 'show'
9
+ render plain: 'show'
10
+ end
11
+
12
+ def doorkeeper_unauthorized_render_options(*)
13
+ end
14
+
15
+ def doorkeeper_forbidden_render_options(*)
10
16
  end
11
17
  end
12
18
 
13
19
  describe 'doorkeeper authorize filter' do
14
20
  context 'accepts token code specified as' do
15
21
  controller do
16
- before_filter :doorkeeper_authorize!
22
+ before_action :doorkeeper_authorize!
17
23
 
18
24
  def index
19
- render text: 'index'
25
+ render plain: 'index'
20
26
  end
21
27
  end
22
28
 
23
29
  let(:token_string) { '1A2BC3' }
24
30
  let(:token) do
25
- double(Doorkeeper::AccessToken, acceptable?: true)
31
+ double(Doorkeeper::AccessToken,
32
+ acceptable?: true, previous_refresh_token: "",
33
+ revoke_previous_refresh_token!: true)
26
34
  end
27
35
 
28
36
  it 'access_token param' do
@@ -58,7 +66,7 @@ describe 'doorkeeper authorize filter' do
58
66
 
59
67
  context 'defined for all actions' do
60
68
  controller do
61
- before_filter :doorkeeper_authorize!
69
+ before_action :doorkeeper_authorize!
62
70
 
63
71
  include ControllerActions
64
72
  end
@@ -92,7 +100,7 @@ describe 'doorkeeper authorize filter' do
92
100
 
93
101
  context 'defined with scopes' do
94
102
  controller do
95
- before_filter -> { doorkeeper_authorize! :write }
103
+ before_action -> { doorkeeper_authorize! :write }
96
104
 
97
105
  include ControllerActions
98
106
  end
@@ -100,16 +108,26 @@ describe 'doorkeeper authorize filter' do
100
108
  let(:token_string) { '1A2DUWE' }
101
109
 
102
110
  it 'allows if the token has particular scopes' do
103
- token = double(Doorkeeper::AccessToken, accessible?: true, scopes: %w(write public))
111
+ token = double(Doorkeeper::AccessToken,
112
+ accessible?: true, scopes: %w(write public),
113
+ previous_refresh_token: "",
114
+ revoke_previous_refresh_token!: true)
104
115
  expect(token).to receive(:acceptable?).with([:write]).and_return(true)
105
- expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
116
+ expect(
117
+ Doorkeeper::AccessToken
118
+ ).to receive(:by_token).with(token_string).and_return(token)
106
119
  get :index, access_token: token_string
107
120
  expect(response).to be_success
108
121
  end
109
122
 
110
123
  it 'does not allow if the token does not include given scope' do
111
- token = double(Doorkeeper::AccessToken, accessible?: true, scopes: ['public'], revoked?: false, expired?: false)
112
- expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
124
+ token = double(Doorkeeper::AccessToken,
125
+ accessible?: true, scopes: ['public'], revoked?: false,
126
+ expired?: false, previous_refresh_token: "",
127
+ revoke_previous_refresh_token!: true)
128
+ expect(
129
+ Doorkeeper::AccessToken
130
+ ).to receive(:by_token).with(token_string).and_return(token)
113
131
  expect(token).to receive(:acceptable?).with([:write]).and_return(false)
114
132
  get :index, access_token: token_string
115
133
  expect(response.status).to eq 403
@@ -119,7 +137,7 @@ describe 'doorkeeper authorize filter' do
119
137
 
120
138
  context 'when custom unauthorized render options are configured' do
121
139
  controller do
122
- before_filter :doorkeeper_authorize!
140
+ before_action :doorkeeper_authorize!
123
141
 
124
142
  include ControllerActions
125
143
  end
@@ -127,6 +145,7 @@ describe 'doorkeeper authorize filter' do
127
145
  context 'with a JSON custom render', token: :invalid do
128
146
  before do
129
147
  module ControllerActions
148
+ remove_method :doorkeeper_unauthorized_render_options
130
149
  def doorkeeper_unauthorized_render_options(error: nil)
131
150
  { json: ActiveSupport::JSON.encode(error_message: error.description) }
132
151
  end
@@ -134,6 +153,7 @@ describe 'doorkeeper authorize filter' do
134
153
  end
135
154
  after do
136
155
  module ControllerActions
156
+ remove_method :doorkeeper_unauthorized_render_options
137
157
  def doorkeeper_unauthorized_render_options(error: nil)
138
158
  end
139
159
  end
@@ -153,13 +173,15 @@ describe 'doorkeeper authorize filter' do
153
173
  context 'with a text custom render', token: :invalid do
154
174
  before do
155
175
  module ControllerActions
176
+ remove_method :doorkeeper_unauthorized_render_options
156
177
  def doorkeeper_unauthorized_render_options(error: nil)
157
- { text: 'Unauthorized' }
178
+ { plain: 'Unauthorized' }
158
179
  end
159
180
  end
160
181
  end
161
182
  after do
162
183
  module ControllerActions
184
+ remove_method :doorkeeper_unauthorized_render_options
163
185
  def doorkeeper_unauthorized_render_options(error: nil)
164
186
  end
165
187
  end
@@ -168,7 +190,7 @@ describe 'doorkeeper authorize filter' do
168
190
  it 'it renders a custom text response', token: :invalid do
169
191
  get :index, access_token: token_string
170
192
  expect(response.status).to eq 401
171
- expect(response.content_type).to eq('text/html')
193
+ expect(response.content_type).to eq('text/plain')
172
194
  expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
173
195
  expect(response.body).to eq('Unauthorized')
174
196
  end
@@ -183,26 +205,30 @@ describe 'doorkeeper authorize filter' do
183
205
 
184
206
  after do
185
207
  module ControllerActions
208
+ remove_method :doorkeeper_forbidden_render_options
186
209
  def doorkeeper_forbidden_render_options(*)
187
210
  end
188
211
  end
189
212
  end
190
213
 
191
214
  controller do
192
- before_filter -> { doorkeeper_authorize! :write }
215
+ before_action -> { doorkeeper_authorize! :write }
193
216
 
194
217
  include ControllerActions
195
218
  end
196
219
 
197
220
  let(:token) do
198
221
  double(Doorkeeper::AccessToken,
199
- accessible?: true, scopes: ['public'], revoked?: false, expired?: false)
222
+ accessible?: true, scopes: ['public'], revoked?: false,
223
+ expired?: false, previous_refresh_token: "",
224
+ revoke_previous_refresh_token!: true)
200
225
  end
201
226
  let(:token_string) { '1A2DUWE' }
202
227
 
203
228
  context 'with a JSON custom render' do
204
229
  before do
205
230
  module ControllerActions
231
+ remove_method :doorkeeper_forbidden_render_options
206
232
  def doorkeeper_forbidden_render_options(*)
207
233
  { json: { error_message: 'Forbidden' } }
208
234
  end
@@ -223,6 +249,7 @@ describe 'doorkeeper authorize filter' do
223
249
  context 'with a status and JSON custom render' do
224
250
  before do
225
251
  module ControllerActions
252
+ remove_method :doorkeeper_forbidden_render_options
226
253
  def doorkeeper_forbidden_render_options(*)
227
254
  { json: { error_message: 'Not Found' },
228
255
  respond_not_found_when_forbidden: true }
@@ -239,8 +266,9 @@ describe 'doorkeeper authorize filter' do
239
266
  context 'with a text custom render' do
240
267
  before do
241
268
  module ControllerActions
269
+ remove_method :doorkeeper_forbidden_render_options
242
270
  def doorkeeper_forbidden_render_options(*)
243
- { text: 'Forbidden' }
271
+ { plain: 'Forbidden' }
244
272
  end
245
273
  end
246
274
  end
@@ -256,8 +284,9 @@ describe 'doorkeeper authorize filter' do
256
284
  context 'with a status and text custom render' do
257
285
  before do
258
286
  module ControllerActions
287
+ remove_method :doorkeeper_forbidden_render_options
259
288
  def doorkeeper_forbidden_render_options(*)
260
- { respond_not_found_when_forbidden: true, text: 'Not Found' }
289
+ { respond_not_found_when_forbidden: true, plain: 'Not Found' }
261
290
  end
262
291
  end
263
292
  end
@@ -64,7 +64,7 @@ describe Doorkeeper::TokensController do
64
64
  describe 'when revoke authorization has failed' do
65
65
  # http://tools.ietf.org/html/rfc7009#section-2.2
66
66
  it 'returns no error response' do
67
- token = double(:token, authorize: false)
67
+ token = double(:token, authorize: false, application_id?: true)
68
68
  allow(controller).to receive(:token) { token }
69
69
 
70
70
  post :revoke
@@ -1,12 +1,12 @@
1
1
  class FullProtectedResourcesController < ApplicationController
2
- before_filter -> { doorkeeper_authorize! :write, :admin }, only: :show
3
- before_filter :doorkeeper_authorize!, only: :index
2
+ before_action -> { doorkeeper_authorize! :write, :admin }, only: :show
3
+ before_action :doorkeeper_authorize!, only: :index
4
4
 
5
5
  def index
6
- render text: 'index'
6
+ render plain: 'index'
7
7
  end
8
8
 
9
9
  def show
10
- render text: 'show'
10
+ render plain: 'show'
11
11
  end
12
12
  end
@@ -12,6 +12,6 @@ class HomeController < ApplicationController
12
12
  end
13
13
 
14
14
  def callback
15
- render text: 'ok'
15
+ render plain: 'ok'
16
16
  end
17
17
  end
@@ -3,7 +3,7 @@ class MetalController < ActionController::Metal
3
3
  include ActionController::Head
4
4
  include Doorkeeper::Rails::Helpers
5
5
 
6
- before_filter :doorkeeper_authorize!
6
+ before_action :doorkeeper_authorize!
7
7
 
8
8
  def index
9
9
  self.response_body = { ok: true }.to_json
@@ -1,11 +1,11 @@
1
1
  class SemiProtectedResourcesController < ApplicationController
2
- before_filter :doorkeeper_authorize!, only: :index
2
+ before_action :doorkeeper_authorize!, only: :index
3
3
 
4
4
  def index
5
- render text: 'protected index'
5
+ render plain: 'protected index'
6
6
  end
7
7
 
8
8
  def show
9
- render text: 'non protected show'
9
+ render plain: 'non protected show'
10
10
  end
11
11
  end
@@ -1,8 +1,4 @@
1
1
  class User < ActiveRecord::Base
2
- if respond_to?(:attr_accessible)
3
- attr_accessible :name, :password
4
- end
5
-
6
2
  def self.authenticate!(name, password)
7
3
  User.where(name: name, password: password).first
8
4
  end
@@ -1,9 +1,8 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- require 'action_controller/railtie'
4
- require 'sprockets/railtie'
3
+ require 'rails/all'
5
4
 
6
- Bundler.require :default
5
+ Bundler.require(*Rails.groups)
7
6
 
8
7
  require 'yaml'
9
8
 
@@ -20,38 +19,5 @@ module Dummy
20
19
  # Settings in config/environments/* take precedence over those specified here.
21
20
  # Application configuration should go into files in config/initializers
22
21
  # -- all .rb files in that directory are automatically loaded.
23
-
24
- # Only load the plugins named here, in the order given (default is alphabetical).
25
- # :all can be used as a placeholder for all plugins not explicitly named.
26
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
27
-
28
- # Activate observers that should always be running.
29
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
30
-
31
- if defined?(ActiveRecord) && Rails.version.to_i < 4
32
- config.active_record.whitelist_attributes = true
33
- end
34
-
35
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
36
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
37
- # config.time_zone = 'Central Time (US & Canada)'
38
-
39
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
40
- config.i18n.load_path += Dir[Rails.root.join('../../', 'config/locales', '*.{rb,yml}').to_s]
41
- # config.i18n.default_locale = :en
42
-
43
- # Configure the default encoding used in templates for Ruby 1.9.
44
- config.encoding = 'utf-8'
45
-
46
- # Configure sensitive parameters which will be filtered from the log file.
47
- config.filter_parameters += [:password]
48
-
49
- # Enable the asset pipeline
50
- config.assets.enabled = true
51
-
52
- # Version of your assets, change this if you want to expire all your assets
53
- config.assets.version = '1.0'
54
-
55
- I18n.enforce_available_locales = false
56
22
  end
57
23
  end
@@ -2,4 +2,4 @@
2
2
  require File.expand_path('../application', __FILE__)
3
3
 
4
4
  # Initialize the rails application
5
- Dummy::Application.initialize!
5
+ Rails.application.initialize!
@@ -7,21 +7,10 @@ Dummy::Application.configure do
7
7
  # and recreated between test runs. Don't rely on the data there!
8
8
  config.cache_classes = true
9
9
 
10
- # Configure static asset server for tests with Cache-Control for performance
11
- config.static_cache_control = 'public, max-age=3600'
12
-
13
- if Rails.version.to_i < 4
14
- # Log error messages when you accidentally call methods on nil
15
- config.whiny_nils = true
16
- end
17
-
18
- if Rails.version.to_i >= 4
19
- # Do not eager load code on boot. This avoids loading your whole application
20
- # just for the purpose of running a single test. If you are using a tool that
21
- # preloads Rails for running tests, you may have to set it to true.
22
- config.eager_load = false
23
- config.i18n.enforce_available_locales = true
24
- end
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
25
14
 
26
15
  # Show full error reports and disable caching
27
16
  config.consider_all_requests_local = true
@@ -0,0 +1,6 @@
1
+ # Require `belongs_to` associations by default. This is a new Rails 5.0
2
+ # default, so it is introduced as a configuration option to ensure that apps
3
+ # made on earlier versions of Rails are not affected when upgrading.
4
+ if Rails.version.to_i >= 5
5
+ Rails.application.config.active_record.belongs_to_required_by_default = true
6
+ end
@@ -30,10 +30,10 @@ Doorkeeper.configure do
30
30
  use_refresh_token
31
31
 
32
32
  # Provide support for an owner to be assigned to each registered application (disabled by default)
33
- # Optional parameter :confirmation => true (default false) if you want to enforce ownership of
33
+ # Optional parameter confirmation: true (default false) if you want to enforce ownership of
34
34
  # a registered application
35
35
  # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
36
- # enable_application_owner :confirmation => false
36
+ # enable_application_owner confirmation: false
37
37
 
38
38
  # Define access token scopes for your provider
39
39
  # For more information go to
@@ -4,29 +4,43 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
4
4
  t.string :name, null: false
5
5
  t.string :uid, null: false
6
6
  t.string :secret, null: false
7
- t.string :redirect_uri, null: false, limit: 2048
8
- t.timestamps
7
+ t.text :redirect_uri, null: false
8
+ t.string :scopes, null: false, default: ''
9
+ t.timestamps null: false
9
10
  end
10
11
 
11
12
  add_index :oauth_applications, :uid, unique: true
12
13
 
13
14
  create_table :oauth_access_grants do |t|
14
15
  t.integer :resource_owner_id, null: false
15
- t.integer :application_id, null: false
16
+ t.references :application, null: false
16
17
  t.string :token, null: false
17
18
  t.integer :expires_in, null: false
18
- t.string :redirect_uri, null: false, limit: 2048
19
+ t.text :redirect_uri, null: false
19
20
  t.datetime :created_at, null: false
20
21
  t.datetime :revoked_at
21
22
  t.string :scopes
22
23
  end
23
24
 
24
25
  add_index :oauth_access_grants, :token, unique: true
26
+ add_foreign_key(
27
+ :oauth_access_grants,
28
+ :oauth_applications,
29
+ column: :application_id,
30
+ )
25
31
 
26
32
  create_table :oauth_access_tokens do |t|
27
33
  t.integer :resource_owner_id
28
- t.integer :application_id
34
+ t.references :application
35
+
36
+ # If you use a custom token generator you may need to change this column
37
+ # from string to text, so that it accepts tokens larger than 255
38
+ # characters. More info on custom token generators in:
39
+ # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
40
+ #
41
+ # t.text :token, null: false
29
42
  t.string :token, null: false
43
+
30
44
  t.string :refresh_token
31
45
  t.integer :expires_in
32
46
  t.datetime :revoked_at
@@ -37,5 +51,10 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
37
51
  add_index :oauth_access_tokens, :token, unique: true
38
52
  add_index :oauth_access_tokens, :resource_owner_id
39
53
  add_index :oauth_access_tokens, :refresh_token, unique: true
54
+ add_foreign_key(
55
+ :oauth_access_tokens,
56
+ :oauth_applications,
57
+ column: :application_id,
58
+ )
40
59
  end
41
60
  end
@@ -0,0 +1,11 @@
1
+ class AddPreviousRefreshTokenToAccessTokens < ActiveRecord::Migration
2
+ def change
3
+ add_column(
4
+ :oauth_access_tokens,
5
+ :previous_refresh_token,
6
+ :string,
7
+ default: "",
8
+ null: false
9
+ )
10
+ end
11
+ end