doorkeeper 3.0.0 → 4.0.0
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.
- checksums.yaml +4 -4
- data/.hound.yml +4 -0
- data/.travis.yml +9 -7
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +10 -3
- data/NEWS.md +79 -2
- data/README.md +56 -51
- data/RELEASING.md +2 -2
- data/Rakefile +1 -1
- data/app/assets/stylesheets/doorkeeper/admin/application.css +1 -5
- data/app/controllers/doorkeeper/application_metal_controller.rb +1 -2
- data/app/controllers/doorkeeper/applications_controller.rb +2 -2
- data/app/controllers/doorkeeper/authorizations_controller.rb +1 -1
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +1 -1
- data/app/helpers/doorkeeper/dashboard_helper.rb +13 -11
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
- data/app/views/layouts/doorkeeper/admin.html.erb +5 -2
- data/config/locales/en.yml +1 -0
- data/doorkeeper.gemspec +7 -7
- data/lib/doorkeeper/config.rb +10 -15
- data/lib/doorkeeper/engine.rb +11 -7
- data/lib/doorkeeper/errors.rb +6 -0
- data/lib/doorkeeper/helpers/controller.rb +7 -1
- data/lib/doorkeeper/models/access_grant_mixin.rb +9 -5
- data/lib/doorkeeper/models/access_token_mixin.rb +28 -22
- data/lib/doorkeeper/models/application_mixin.rb +3 -7
- data/lib/doorkeeper/models/concerns/expirable.rb +2 -2
- data/lib/doorkeeper/models/concerns/ownership.rb +6 -1
- data/lib/doorkeeper/models/concerns/revocable.rb +19 -2
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_code_request.rb +10 -5
- data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +3 -4
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +2 -1
- data/lib/doorkeeper/oauth/client_credentials_request.rb +7 -4
- data/lib/doorkeeper/oauth/code_response.rb +13 -14
- data/lib/doorkeeper/oauth/error.rb +5 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +2 -1
- data/lib/doorkeeper/oauth/password_access_token_request.rb +6 -10
- data/lib/doorkeeper/oauth/refresh_token_request.rb +29 -12
- data/lib/doorkeeper/oauth/scopes.rb +2 -2
- data/lib/doorkeeper/oauth/token.rb +6 -5
- data/lib/doorkeeper/oauth/token_response.rb +1 -1
- data/lib/doorkeeper/orm/active_record/access_grant.rb +2 -2
- data/lib/doorkeeper/orm/active_record/access_token.rb +10 -2
- data/lib/doorkeeper/orm/active_record/application.rb +4 -9
- data/lib/doorkeeper/orm/active_record.rb +0 -15
- data/lib/doorkeeper/rails/helpers.rb +13 -3
- data/lib/doorkeeper/rails/routes/mapper.rb +1 -1
- data/lib/doorkeeper/rails/routes.rb +2 -1
- data/lib/doorkeeper/request/authorization_code.rb +10 -15
- data/lib/doorkeeper/request/client_credentials.rb +9 -15
- data/lib/doorkeeper/request/code.rb +7 -13
- data/lib/doorkeeper/request/password.rb +18 -13
- data/lib/doorkeeper/request/refresh_token.rb +11 -13
- data/lib/doorkeeper/request/strategy.rb +17 -0
- data/lib/doorkeeper/request/token.rb +7 -13
- data/lib/doorkeeper/request.rb +18 -8
- data/lib/doorkeeper/server.rb +2 -2
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +1 -1
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -0
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +1 -1
- data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb +11 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +2 -2
- data/lib/generators/doorkeeper/templates/migration.rb +23 -5
- data/spec/controllers/authorizations_controller_spec.rb +0 -14
- data/spec/controllers/protected_resources_controller_spec.rb +138 -15
- data/spec/controllers/tokens_controller_spec.rb +30 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -4
- data/spec/dummy/app/controllers/home_controller.rb +1 -1
- data/spec/dummy/app/controllers/metal_controller.rb +1 -1
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +3 -3
- data/spec/dummy/app/models/user.rb +0 -4
- data/spec/dummy/config/application.rb +2 -36
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/test.rb +4 -15
- data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +6 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +2 -2
- data/spec/dummy/db/migrate/{20130902165751_create_doorkeeper_tables.rb → 20151223192035_create_doorkeeper_tables.rb} +24 -5
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +11 -0
- data/spec/dummy/db/schema.rb +23 -22
- data/spec/lib/config_spec.rb +2 -2
- data/spec/lib/models/revocable_spec.rb +27 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials/creator_spec.rb +25 -1
- data/spec/lib/oauth/code_response_spec.rb +34 -0
- data/spec/lib/oauth/error_response_spec.rb +7 -7
- data/spec/lib/oauth/error_spec.rb +9 -5
- data/spec/lib/oauth/password_access_token_request_spec.rb +5 -5
- data/spec/lib/oauth/refresh_token_request_spec.rb +34 -3
- data/spec/lib/oauth/scopes_spec.rb +1 -2
- data/spec/lib/oauth/token_spec.rb +12 -5
- data/spec/lib/request/strategy_spec.rb +53 -0
- data/spec/lib/server_spec.rb +1 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +5 -5
- data/spec/models/doorkeeper/access_token_spec.rb +49 -5
- data/spec/models/doorkeeper/application_spec.rb +2 -10
- data/spec/requests/flows/authorization_code_spec.rb +26 -0
- data/spec/requests/flows/password_spec.rb +26 -5
- data/spec/requests/flows/refresh_token_spec.rb +95 -17
- data/spec/spec_helper_integration.rb +10 -0
- data/spec/support/helpers/model_helper.rb +27 -5
- data/spec/support/http_method_shim.rb +24 -0
- data/spec/support/shared/controllers_shared_context.rb +13 -4
- data/spec/support/shared/models_shared_examples.rb +1 -1
- metadata +46 -38
- data/lib/generators/doorkeeper/application_scopes_generator.rb +0 -34
- data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +0 -5
- data/spec/dummy/db/migrate/20141209001746_add_scopes_to_oauth_applications.rb +0 -5
- /data/spec/dummy/db/migrate/{20130902175349_add_owner_to_application.rb → 20151223200000_add_owner_to_application.rb} +0 -0
@@ -2,27 +2,35 @@ require 'spec_helper_integration'
|
|
2
2
|
|
3
3
|
module ControllerActions
|
4
4
|
def index
|
5
|
-
render
|
5
|
+
render plain: 'index'
|
6
6
|
end
|
7
7
|
|
8
8
|
def show
|
9
|
-
render
|
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
|
-
|
22
|
+
before_action :doorkeeper_authorize!
|
17
23
|
|
18
24
|
def index
|
19
|
-
render
|
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,
|
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
|
-
|
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
|
-
|
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,
|
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(
|
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,
|
112
|
-
|
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
|
-
|
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,25 +173,128 @@ 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
|
-
{
|
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
|
166
188
|
end
|
167
189
|
|
168
|
-
it 'it renders a custom
|
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/
|
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
|
175
197
|
end
|
176
198
|
end
|
199
|
+
|
200
|
+
context 'when custom forbidden render options are configured' do
|
201
|
+
before do
|
202
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
203
|
+
expect(token).to receive(:acceptable?).with([:write]).and_return(false)
|
204
|
+
end
|
205
|
+
|
206
|
+
after do
|
207
|
+
module ControllerActions
|
208
|
+
remove_method :doorkeeper_forbidden_render_options
|
209
|
+
def doorkeeper_forbidden_render_options(*)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
controller do
|
215
|
+
before_action -> { doorkeeper_authorize! :write }
|
216
|
+
|
217
|
+
include ControllerActions
|
218
|
+
end
|
219
|
+
|
220
|
+
let(:token) do
|
221
|
+
double(Doorkeeper::AccessToken,
|
222
|
+
accessible?: true, scopes: ['public'], revoked?: false,
|
223
|
+
expired?: false, previous_refresh_token: "",
|
224
|
+
revoke_previous_refresh_token!: true)
|
225
|
+
end
|
226
|
+
let(:token_string) { '1A2DUWE' }
|
227
|
+
|
228
|
+
context 'with a JSON custom render' do
|
229
|
+
before do
|
230
|
+
module ControllerActions
|
231
|
+
remove_method :doorkeeper_forbidden_render_options
|
232
|
+
def doorkeeper_forbidden_render_options(*)
|
233
|
+
{ json: { error_message: 'Forbidden' } }
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'renders a custom JSON response' do
|
239
|
+
get :index, access_token: token_string
|
240
|
+
expect(response.header).to_not include('WWW-Authenticate')
|
241
|
+
expect(response.content_type).to eq('application/json')
|
242
|
+
expect(response.status).to eq 403
|
243
|
+
parsed_body = JSON.parse(response.body)
|
244
|
+
expect(parsed_body).not_to be_nil
|
245
|
+
expect(parsed_body['error_message']).to match('Forbidden')
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'with a status and JSON custom render' do
|
250
|
+
before do
|
251
|
+
module ControllerActions
|
252
|
+
remove_method :doorkeeper_forbidden_render_options
|
253
|
+
def doorkeeper_forbidden_render_options(*)
|
254
|
+
{ json: { error_message: 'Not Found' },
|
255
|
+
respond_not_found_when_forbidden: true }
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'overrides the default status code' do
|
261
|
+
get :index, access_token: token_string
|
262
|
+
expect(response.status).to eq 404
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
context 'with a text custom render' do
|
267
|
+
before do
|
268
|
+
module ControllerActions
|
269
|
+
remove_method :doorkeeper_forbidden_render_options
|
270
|
+
def doorkeeper_forbidden_render_options(*)
|
271
|
+
{ plain: 'Forbidden' }
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'renders a custom status code and text response' do
|
277
|
+
get :index, access_token: token_string
|
278
|
+
expect(response.header).to_not include('WWW-Authenticate')
|
279
|
+
expect(response.status).to eq 403
|
280
|
+
expect(response.body).to eq('Forbidden')
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
context 'with a status and text custom render' do
|
285
|
+
before do
|
286
|
+
module ControllerActions
|
287
|
+
remove_method :doorkeeper_forbidden_render_options
|
288
|
+
def doorkeeper_forbidden_render_options(*)
|
289
|
+
{ respond_not_found_when_forbidden: true, plain: 'Not Found' }
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'overrides the default status code' do
|
295
|
+
get :index, access_token: token_string
|
296
|
+
expect(response.status).to eq 404
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
177
300
|
end
|
@@ -31,6 +31,36 @@ describe Doorkeeper::TokensController do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
describe 'when there is a failure due to a custom error' do
|
35
|
+
it 'returns the error response with a custom message' do
|
36
|
+
# I18n looks for `doorkeeper.errors.messages.custom_message` in locale files
|
37
|
+
custom_message = "my_message"
|
38
|
+
allow(I18n).to receive(:translate).
|
39
|
+
with(
|
40
|
+
custom_message,
|
41
|
+
hash_including(scope: [:doorkeeper, :errors, :messages]),
|
42
|
+
).
|
43
|
+
and_return('Authorization custom message')
|
44
|
+
|
45
|
+
doorkeeper_error = Doorkeeper::Errors::DoorkeeperError.new(custom_message)
|
46
|
+
|
47
|
+
strategy = double(:strategy)
|
48
|
+
request = double(token_request: strategy)
|
49
|
+
allow(strategy).to receive(:authorize).and_raise(doorkeeper_error)
|
50
|
+
allow(controller).to receive(:server).and_return(request)
|
51
|
+
|
52
|
+
post :create
|
53
|
+
|
54
|
+
expected_response_body = {
|
55
|
+
"error" => custom_message,
|
56
|
+
"error_description" => "Authorization custom message"
|
57
|
+
}
|
58
|
+
expect(response.status).to eq 401
|
59
|
+
expect(response.headers['WWW-Authenticate']).to match(/Bearer/)
|
60
|
+
expect(JSON.load(response.body)).to eq expected_response_body
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
34
64
|
describe 'when revoke authorization has failed' do
|
35
65
|
# http://tools.ietf.org/html/rfc7009#section-2.2
|
36
66
|
it 'returns no error response' do
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class FullProtectedResourcesController < ApplicationController
|
2
|
-
|
3
|
-
|
2
|
+
before_action -> { doorkeeper_authorize! :write, :admin }, only: :show
|
3
|
+
before_action :doorkeeper_authorize!, only: :index
|
4
4
|
|
5
5
|
def index
|
6
|
-
render
|
6
|
+
render plain: 'index'
|
7
7
|
end
|
8
8
|
|
9
9
|
def show
|
10
|
-
render
|
10
|
+
render plain: 'show'
|
11
11
|
end
|
12
12
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class SemiProtectedResourcesController < ApplicationController
|
2
|
-
|
2
|
+
before_action :doorkeeper_authorize!, only: :index
|
3
3
|
|
4
4
|
def index
|
5
|
-
render
|
5
|
+
render plain: 'protected index'
|
6
6
|
end
|
7
7
|
|
8
8
|
def show
|
9
|
-
render
|
9
|
+
render plain: 'non protected show'
|
10
10
|
end
|
11
11
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'sprockets/railtie'
|
3
|
+
require 'rails/all'
|
5
4
|
|
6
|
-
Bundler.require
|
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
|
@@ -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
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
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 :
|
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 :
|
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.
|
8
|
-
t.
|
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.
|
16
|
+
t.references :application, null: false
|
16
17
|
t.string :token, null: false
|
17
18
|
t.integer :expires_in, null: false
|
18
|
-
t.
|
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.
|
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
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,55 +11,56 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20160320211015) do
|
15
15
|
|
16
|
-
create_table "oauth_access_grants", force:
|
17
|
-
t.integer "resource_owner_id",
|
18
|
-
t.integer "application_id",
|
19
|
-
t.string "token",
|
20
|
-
t.integer "expires_in",
|
21
|
-
t.
|
22
|
-
t.datetime "created_at",
|
16
|
+
create_table "oauth_access_grants", force: :cascade do |t|
|
17
|
+
t.integer "resource_owner_id", null: false
|
18
|
+
t.integer "application_id", null: false
|
19
|
+
t.string "token", null: false
|
20
|
+
t.integer "expires_in", null: false
|
21
|
+
t.text "redirect_uri", null: false
|
22
|
+
t.datetime "created_at", null: false
|
23
23
|
t.datetime "revoked_at"
|
24
24
|
t.string "scopes"
|
25
25
|
end
|
26
26
|
|
27
27
|
add_index "oauth_access_grants", ["token"], name: "index_oauth_access_grants_on_token", unique: true
|
28
28
|
|
29
|
-
create_table "oauth_access_tokens", force:
|
29
|
+
create_table "oauth_access_tokens", force: :cascade do |t|
|
30
30
|
t.integer "resource_owner_id"
|
31
31
|
t.integer "application_id"
|
32
|
-
t.string "token",
|
32
|
+
t.string "token", null: false
|
33
33
|
t.string "refresh_token"
|
34
34
|
t.integer "expires_in"
|
35
35
|
t.datetime "revoked_at"
|
36
|
-
t.datetime "created_at",
|
36
|
+
t.datetime "created_at", null: false
|
37
37
|
t.string "scopes"
|
38
|
+
t.string "previous_refresh_token", default: "", null: false
|
38
39
|
end
|
39
40
|
|
40
41
|
add_index "oauth_access_tokens", ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true
|
41
42
|
add_index "oauth_access_tokens", ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id"
|
42
43
|
add_index "oauth_access_tokens", ["token"], name: "index_oauth_access_tokens_on_token", unique: true
|
43
44
|
|
44
|
-
create_table "oauth_applications", force:
|
45
|
-
t.string "name",
|
46
|
-
t.string "uid",
|
47
|
-
t.string "secret",
|
48
|
-
t.
|
49
|
-
t.
|
50
|
-
t.datetime "
|
45
|
+
create_table "oauth_applications", force: :cascade do |t|
|
46
|
+
t.string "name", null: false
|
47
|
+
t.string "uid", null: false
|
48
|
+
t.string "secret", null: false
|
49
|
+
t.text "redirect_uri", null: false
|
50
|
+
t.string "scopes", default: "", null: false
|
51
|
+
t.datetime "created_at"
|
52
|
+
t.datetime "updated_at"
|
51
53
|
t.integer "owner_id"
|
52
54
|
t.string "owner_type"
|
53
|
-
t.string "scopes", default: "", null: false
|
54
55
|
end
|
55
56
|
|
56
57
|
add_index "oauth_applications", ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type"
|
57
58
|
add_index "oauth_applications", ["uid"], name: "index_oauth_applications_on_uid", unique: true
|
58
59
|
|
59
|
-
create_table "users", force:
|
60
|
+
create_table "users", force: :cascade do |t|
|
60
61
|
t.string "name"
|
61
|
-
t.datetime "created_at"
|
62
|
-
t.datetime "updated_at"
|
62
|
+
t.datetime "created_at"
|
63
|
+
t.datetime "updated_at"
|
63
64
|
t.string "password"
|
64
65
|
end
|
65
66
|
|
data/spec/lib/config_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Doorkeeper, 'configuration' do
|
|
8
8
|
block = proc {}
|
9
9
|
Doorkeeper.configure do
|
10
10
|
orm DOORKEEPER_ORM
|
11
|
-
resource_owner_authenticator
|
11
|
+
resource_owner_authenticator(&block)
|
12
12
|
end
|
13
13
|
expect(subject.authenticate_resource_owner).to eq(block)
|
14
14
|
end
|
@@ -149,7 +149,7 @@ describe Doorkeeper, 'configuration' do
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
-
describe '
|
152
|
+
describe 'access_token_methods' do
|
153
153
|
it 'has defaults order' do
|
154
154
|
expect(subject.access_token_methods).to eq([:from_bearer_authorization, :from_access_token_param, :from_bearer_param])
|
155
155
|
end
|