doorkeeper 1.4.1 → 2.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 +3 -0
- data/.travis.yml +38 -10
- data/CHANGELOG.md +43 -1
- data/CONTRIBUTING.md +35 -0
- data/Gemfile +4 -26
- data/README.md +21 -55
- data/Rakefile +3 -1
- data/app/controllers/doorkeeper/application_controller.rb +2 -2
- data/app/controllers/doorkeeper/applications_controller.rb +4 -5
- data/app/controllers/doorkeeper/authorizations_controller.rb +4 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +2 -2
- data/app/helpers/doorkeeper/{form_errors_helper.rb → dashboard_helper.rb} +5 -1
- data/app/validators/redirect_uri_validator.rb +6 -0
- data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -1
- data/app/views/doorkeeper/applications/_form.html.erb +3 -3
- data/app/views/doorkeeper/applications/index.html.erb +1 -1
- data/config/locales/en.yml +6 -3
- data/doorkeeper.gemspec +3 -3
- data/gemfiles/Gemfile.common.rb +11 -0
- data/gemfiles/Gemfile.mongo_mapper.rb +5 -0
- data/gemfiles/Gemfile.mongoid2.rb +5 -0
- data/gemfiles/Gemfile.mongoid3.rb +4 -0
- data/gemfiles/Gemfile.mongoid4.rb +5 -0
- data/lib/doorkeeper/config.rb +34 -24
- data/lib/doorkeeper/engine.rb +1 -2
- data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb +12 -0
- data/lib/doorkeeper/models/access_grant_mixin.rb +36 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +122 -0
- data/lib/doorkeeper/models/application_mixin.rb +60 -0
- data/lib/doorkeeper/models/{expirable.rb → concerns/expirable.rb} +6 -5
- data/lib/doorkeeper/models/{ownership.rb → concerns/ownership.rb} +7 -7
- data/lib/doorkeeper/models/{revocable.rb → concerns/revocable.rb} +1 -1
- data/lib/doorkeeper/models/concerns/scopes.rb +17 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +6 -6
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
- data/lib/doorkeeper/oauth/pre_authorization.rb +5 -1
- data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -6
- data/lib/doorkeeper/oauth/scopes.rb +6 -1
- data/lib/doorkeeper/oauth/token.rb +3 -2
- data/lib/doorkeeper/orm/active_record/access_grant.rb +7 -0
- data/lib/doorkeeper/orm/active_record/access_token.rb +21 -0
- data/lib/doorkeeper/{models → orm}/active_record/application.rb +1 -3
- data/lib/doorkeeper/orm/active_record.rb +17 -0
- data/lib/doorkeeper/{models → orm}/mongo_mapper/access_grant.rb +4 -5
- data/lib/doorkeeper/{models → orm}/mongo_mapper/access_token.rb +12 -17
- data/lib/doorkeeper/{models → orm}/mongo_mapper/application.rb +3 -4
- data/lib/doorkeeper/orm/mongo_mapper.rb +11 -0
- data/lib/doorkeeper/{models → orm}/mongoid2/access_grant.rb +5 -3
- data/lib/doorkeeper/{models → orm}/mongoid2/access_token.rb +10 -12
- data/lib/doorkeeper/{models → orm}/mongoid2/application.rb +3 -0
- data/lib/doorkeeper/orm/mongoid2/concerns/scopes.rb +30 -0
- data/lib/doorkeeper/orm/mongoid2.rb +11 -0
- data/lib/doorkeeper/orm/mongoid3/access_grant.rb +22 -0
- data/lib/doorkeeper/orm/mongoid3/access_token.rb +37 -0
- data/lib/doorkeeper/{models/mongoid3_4 → orm/mongoid3}/application.rb +3 -0
- data/lib/doorkeeper/orm/mongoid3/concerns/scopes.rb +30 -0
- data/lib/doorkeeper/orm/mongoid3.rb +11 -0
- data/lib/doorkeeper/orm/mongoid4/access_grant.rb +22 -0
- data/lib/doorkeeper/orm/mongoid4/access_token.rb +37 -0
- data/lib/doorkeeper/orm/mongoid4/application.rb +25 -0
- data/lib/doorkeeper/orm/mongoid4/concerns/scopes.rb +17 -0
- data/lib/doorkeeper/orm/mongoid4.rb +11 -0
- data/lib/doorkeeper/rails/helpers.rb +63 -0
- data/lib/doorkeeper/rails/routes.rb +1 -12
- data/lib/doorkeeper/request/code.rb +0 -1
- data/lib/doorkeeper/request/token.rb +0 -1
- data/lib/doorkeeper/server.rb +1 -1
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +15 -6
- data/lib/generators/doorkeeper/application_owner_generator.rb +4 -1
- data/lib/generators/doorkeeper/application_scopes_generator.rb +34 -0
- data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +5 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +8 -1
- data/lib/generators/doorkeeper/templates/migration.rb +1 -0
- data/lib/generators/doorkeeper/views_generator.rb +4 -5
- data/spec/controllers/applications_controller_spec.rb +7 -7
- data/spec/controllers/protected_resources_controller_spec.rb +25 -175
- data/spec/controllers/tokens_controller_spec.rb +15 -9
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/controllers/metal_controller.rb +2 -2
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/models/user.rb +5 -5
- data/spec/dummy/config/application.rb +3 -1
- data/spec/dummy/config/boot.rb +4 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20141209001746_add_scopes_to_oauth_applications.rb +5 -0
- data/spec/dummy/db/schema.rb +41 -40
- data/spec/factories.rb +24 -0
- data/spec/lib/config_spec.rb +30 -10
- data/spec/lib/models/expirable_spec.rb +1 -1
- data/spec/lib/models/revocable_spec.rb +8 -3
- data/spec/lib/models/scopes_spec.rb +3 -3
- data/spec/lib/oauth/client_spec.rb +1 -1
- data/spec/lib/oauth/password_access_token_request_spec.rb +1 -1
- data/spec/lib/oauth/pre_authorization_spec.rb +43 -9
- data/spec/lib/oauth/token_request_spec.rb +28 -1
- data/spec/lib/oauth/token_spec.rb +1 -1
- data/spec/models/doorkeeper/application_spec.rb +16 -1
- data/spec/requests/applications/applications_request_spec.rb +6 -4
- data/spec/requests/flows/implicit_grant_spec.rb +32 -0
- data/spec/requests/flows/refresh_token_spec.rb +12 -3
- data/spec/spec_helper_integration.rb +8 -2
- data/spec/support/shared/controllers_shared_context.rb +2 -2
- data/spec/validators/redirect_uri_validator_spec.rb +30 -3
- metadata +52 -39
- data/lib/doorkeeper/doorkeeper_for.rb +0 -69
- data/lib/doorkeeper/helpers/filter.rb +0 -64
- data/lib/doorkeeper/models/access_grant.rb +0 -30
- data/lib/doorkeeper/models/access_token.rb +0 -106
- data/lib/doorkeeper/models/active_record/access_grant.rb +0 -9
- data/lib/doorkeeper/models/active_record/access_token.rb +0 -25
- data/lib/doorkeeper/models/application.rb +0 -40
- data/lib/doorkeeper/models/mongoid/scopes.rb +0 -15
- data/lib/doorkeeper/models/mongoid/version.rb +0 -15
- data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +0 -27
- data/lib/doorkeeper/models/mongoid3_4/access_token.rb +0 -46
- data/lib/doorkeeper/models/scopes.rb +0 -21
- data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +0 -12
- data/script/rails +0 -5
- data/script/run_all +0 -14
- data/spec/factories/access_grant.rb +0 -9
- data/spec/factories/access_token.rb +0 -11
- data/spec/factories/application.rb +0 -6
- /data/lib/{generators/doorkeeper → doorkeeper/generators/doorkeeper/mongo_mapper}/templates/indexes.rb +0 -0
- /data/lib/doorkeeper/models/{accessible.rb → concerns/accessible.rb} +0 -0
@@ -1,6 +1,7 @@
|
|
1
1
|
Doorkeeper.configure do
|
2
2
|
# Change the ORM that doorkeeper will use.
|
3
|
-
# Currently supported options are :active_record, :mongoid2, :mongoid3,
|
3
|
+
# Currently supported options are :active_record, :mongoid2, :mongoid3,
|
4
|
+
# :mongoid4, :mongo_mapper
|
4
5
|
orm :active_record
|
5
6
|
|
6
7
|
# This block will be called to check whether the resource owner is authenticated or not.
|
@@ -63,6 +64,12 @@ Doorkeeper.configure do
|
|
63
64
|
#
|
64
65
|
# native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
|
65
66
|
|
67
|
+
# Forces the usage of the HTTPS protocol in non-native redirect uris (enabled
|
68
|
+
# by default in non-development environments). OAuth2 delegates security in
|
69
|
+
# communication to the HTTPS protocol so it is wise to keep this enabled.
|
70
|
+
#
|
71
|
+
# force_ssl_in_redirect_uri !Rails.env.development?
|
72
|
+
|
66
73
|
# Specify what grant flows are enabled in array of Strings. The valid
|
67
74
|
# strings and the flows they enable are:
|
68
75
|
#
|
@@ -1,14 +1,13 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
module Generators
|
3
3
|
class ViewsGenerator < ::Rails::Generators::Base
|
4
|
-
source_root File.expand_path('../../../../app/views
|
4
|
+
source_root File.expand_path('../../../../app/views', __FILE__)
|
5
5
|
|
6
|
-
desc 'Copies default Doorkeeper views to your application.'
|
6
|
+
desc 'Copies default Doorkeeper views and layouts to your application.'
|
7
7
|
|
8
8
|
def manifest
|
9
|
-
directory '
|
10
|
-
directory '
|
11
|
-
directory 'authorized_applications', 'app/views/doorkeeper/authorized_applications'
|
9
|
+
directory 'doorkeeper', 'app/views/doorkeeper'
|
10
|
+
directory 'layouts/doorkeeper', 'app/views/layouts/doorkeeper'
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|
@@ -16,9 +16,9 @@ module Doorkeeper
|
|
16
16
|
|
17
17
|
it 'does not create application' do
|
18
18
|
expect do
|
19
|
-
post :create,
|
19
|
+
post :create, doorkeeper_application: {
|
20
20
|
name: 'Example',
|
21
|
-
redirect_uri: '
|
21
|
+
redirect_uri: 'https://example.com' }
|
22
22
|
end.to_not change { Doorkeeper::Application.count }
|
23
23
|
end
|
24
24
|
end
|
@@ -30,16 +30,16 @@ module Doorkeeper
|
|
30
30
|
|
31
31
|
it 'creates application' do
|
32
32
|
expect do
|
33
|
-
post :create,
|
33
|
+
post :create, doorkeeper_application: {
|
34
34
|
name: 'Example',
|
35
|
-
redirect_uri: '
|
35
|
+
redirect_uri: 'https://example.com' }
|
36
36
|
end.to change { Doorkeeper::Application.count }.by(1)
|
37
37
|
expect(response).to be_redirect
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'does not allow mass assignment of uid or secret' do
|
41
41
|
application = FactoryGirl.create(:application)
|
42
|
-
put :update, id: application.id,
|
42
|
+
put :update, id: application.id, doorkeeper_application: {
|
43
43
|
uid: '1A2B3C4D',
|
44
44
|
secret: '1A2B3C4D' }
|
45
45
|
|
@@ -48,9 +48,9 @@ module Doorkeeper
|
|
48
48
|
|
49
49
|
it 'updates application' do
|
50
50
|
application = FactoryGirl.create(:application)
|
51
|
-
put :update, id: application.id,
|
51
|
+
put :update, id: application.id, doorkeeper_application: {
|
52
52
|
name: 'Example',
|
53
|
-
redirect_uri: '
|
53
|
+
redirect_uri: 'https://example.com' }
|
54
54
|
expect(application.reload.name).to eq 'Example'
|
55
55
|
end
|
56
56
|
end
|
@@ -10,66 +10,10 @@ module ControllerActions
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
context 'with valid token', token: :valid do
|
15
|
-
it 'allows into index action' do
|
16
|
-
get :index, access_token: token_string
|
17
|
-
expect(response).to be_success
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'allows into show action' do
|
21
|
-
get :show, id: '3', access_token: token_string
|
22
|
-
expect(response).to be_success
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'with invalid token', token: :invalid do
|
27
|
-
include_context 'invalid token'
|
28
|
-
|
29
|
-
it 'does not allow into index action' do
|
30
|
-
get :index, access_token: token_string
|
31
|
-
expect(response.status).to eq 401
|
32
|
-
expect(response.headers['WWW-Authenticate']).to match(/^Bearer/)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'allows into show action' do
|
36
|
-
get :show, id: '5', access_token: token_string
|
37
|
-
expect(response).to be_success
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
shared_examples 'specified with except' do
|
43
|
-
context 'with valid token', token: :valid do
|
44
|
-
it 'allows into index action' do
|
45
|
-
get :index, access_token: token_string
|
46
|
-
expect(response).to be_success
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'allows into show action' do
|
50
|
-
get :show, id: '4', access_token: token_string
|
51
|
-
expect(response).to be_success
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'with invalid token', token: :invalid do
|
56
|
-
it 'allows into index action' do
|
57
|
-
get :index, access_token: token_string
|
58
|
-
expect(response).to be_success
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'does not allow into show action' do
|
62
|
-
get :show, id: '14', access_token: token_string
|
63
|
-
expect(response.status).to eq 401
|
64
|
-
expect(response.headers['WWW-Authenticate']).to match(/^Bearer/)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe 'Doorkeeper_for helper' do
|
13
|
+
describe 'doorkeeper authorize filter' do
|
70
14
|
context 'accepts token code specified as' do
|
71
15
|
controller do
|
72
|
-
|
16
|
+
before_filter :doorkeeper_authorize!
|
73
17
|
|
74
18
|
def index
|
75
19
|
render text: 'index'
|
@@ -82,39 +26,39 @@ describe 'Doorkeeper_for helper' do
|
|
82
26
|
end
|
83
27
|
|
84
28
|
it 'access_token param' do
|
85
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
29
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
86
30
|
get :index, access_token: token_string
|
87
31
|
end
|
88
32
|
|
89
33
|
it 'bearer_token param' do
|
90
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
34
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
91
35
|
get :index, bearer_token: token_string
|
92
36
|
end
|
93
37
|
|
94
38
|
it 'Authorization header' do
|
95
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
39
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
96
40
|
request.env['HTTP_AUTHORIZATION'] = "Bearer #{token_string}"
|
97
41
|
get :index
|
98
42
|
end
|
99
43
|
|
100
44
|
it 'different kind of Authorization header' do
|
101
|
-
expect(Doorkeeper::AccessToken).not_to receive(:
|
45
|
+
expect(Doorkeeper::AccessToken).not_to receive(:by_token)
|
102
46
|
request.env['HTTP_AUTHORIZATION'] = "MAC #{token_string}"
|
103
47
|
get :index
|
104
48
|
end
|
105
49
|
|
106
50
|
it 'does not change Authorization header value' do
|
107
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
51
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).exactly(2).times.and_return(token)
|
108
52
|
request.env['HTTP_AUTHORIZATION'] = "Bearer #{token_string}"
|
109
53
|
get :index
|
110
|
-
controller.send(:remove_instance_variable, :@
|
54
|
+
controller.send(:remove_instance_variable, :@_doorkeeper_token)
|
111
55
|
get :index
|
112
56
|
end
|
113
57
|
end
|
114
58
|
|
115
59
|
context 'defined for all actions' do
|
116
60
|
controller do
|
117
|
-
|
61
|
+
before_filter :doorkeeper_authorize!
|
118
62
|
|
119
63
|
include ControllerActions
|
120
64
|
end
|
@@ -146,27 +90,9 @@ describe 'Doorkeeper_for helper' do
|
|
146
90
|
end
|
147
91
|
end
|
148
92
|
|
149
|
-
context 'defined only for index action' do
|
150
|
-
controller do
|
151
|
-
doorkeeper_for :index
|
152
|
-
|
153
|
-
include ControllerActions
|
154
|
-
end
|
155
|
-
include_examples 'specified for particular actions'
|
156
|
-
end
|
157
|
-
|
158
|
-
context 'defined for actions except index' do
|
159
|
-
controller do
|
160
|
-
doorkeeper_for :all, except: :index
|
161
|
-
|
162
|
-
include ControllerActions
|
163
|
-
end
|
164
|
-
include_examples 'specified with except'
|
165
|
-
end
|
166
|
-
|
167
93
|
context 'defined with scopes' do
|
168
94
|
controller do
|
169
|
-
|
95
|
+
before_filter -> { doorkeeper_authorize! :write }
|
170
96
|
|
171
97
|
include ControllerActions
|
172
98
|
end
|
@@ -175,16 +101,16 @@ describe 'Doorkeeper_for helper' do
|
|
175
101
|
|
176
102
|
it 'allows if the token has particular scopes' do
|
177
103
|
token = double(Doorkeeper::AccessToken, accessible?: true, scopes: %w(write public))
|
178
|
-
expect(token).to receive(:acceptable?).with([
|
179
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
104
|
+
expect(token).to receive(:acceptable?).with([:write]).and_return(true)
|
105
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
180
106
|
get :index, access_token: token_string
|
181
107
|
expect(response).to be_success
|
182
108
|
end
|
183
109
|
|
184
110
|
it 'does not allow if the token does not include given scope' do
|
185
111
|
token = double(Doorkeeper::AccessToken, accessible?: true, scopes: ['public'], revoked?: false, expired?: false)
|
186
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
187
|
-
expect(token).to receive(:acceptable?).with([
|
112
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
113
|
+
expect(token).to receive(:acceptable?).with([:write]).and_return(false)
|
188
114
|
get :index, access_token: token_string
|
189
115
|
expect(response.status).to eq 403
|
190
116
|
expect(response.header).to_not include('WWW-Authenticate')
|
@@ -193,7 +119,7 @@ describe 'Doorkeeper_for helper' do
|
|
193
119
|
|
194
120
|
context 'when custom unauthorized render options are configured' do
|
195
121
|
controller do
|
196
|
-
|
122
|
+
before_filter :doorkeeper_authorize!
|
197
123
|
|
198
124
|
include ControllerActions
|
199
125
|
end
|
@@ -212,7 +138,6 @@ describe 'Doorkeeper_for helper' do
|
|
212
138
|
expect(parsed_body).not_to be_nil
|
213
139
|
expect(parsed_body['error']).to eq('Unauthorized')
|
214
140
|
end
|
215
|
-
|
216
141
|
end
|
217
142
|
|
218
143
|
context 'with a text custom render', token: :invalid do
|
@@ -230,91 +155,16 @@ describe 'Doorkeeper_for helper' do
|
|
230
155
|
end
|
231
156
|
end
|
232
157
|
|
233
|
-
context '
|
234
|
-
controller
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
true
|
244
|
-
end
|
245
|
-
|
246
|
-
def the_false
|
247
|
-
false
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
context 'with valid token', token: :valid do
|
252
|
-
it 'enables access if passed block evaluates to false' do
|
253
|
-
get :index, access_token: token_string
|
254
|
-
expect(response).to be_success
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'enables access if passed block evaluates to true' do
|
258
|
-
get :show, id: 1, access_token: token_string
|
259
|
-
expect(response).to be_success
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context 'with invalid token', token: :invalid do
|
264
|
-
it 'enables access if passed block evaluates to false' do
|
265
|
-
get :index, access_token: token_string
|
266
|
-
expect(response).to be_success
|
267
|
-
end
|
268
|
-
|
269
|
-
it 'does not enable access if passed block evaluates to true' do
|
270
|
-
get :show, id: 3, access_token: token_string
|
271
|
-
expect(response.status).to eq 401
|
272
|
-
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
context 'when defined with conditional unless block' do
|
278
|
-
controller do
|
279
|
-
doorkeeper_for :index, unless: -> { the_false }
|
280
|
-
doorkeeper_for :show, unless: -> { the_true }
|
281
|
-
|
282
|
-
include ControllerActions
|
283
|
-
|
284
|
-
def the_true
|
285
|
-
true
|
286
|
-
end
|
287
|
-
|
288
|
-
private
|
289
|
-
|
290
|
-
def the_false
|
291
|
-
false
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
context 'with valid token', token: :valid do
|
296
|
-
it 'allows access if passed block evaluates to false' do
|
297
|
-
get :index, access_token: token_string
|
298
|
-
expect(response).to be_success
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'allows access if passed block evaluates to true' do
|
302
|
-
get :show, id: 1, access_token: token_string
|
303
|
-
expect(response).to be_success
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
context 'with invalid token', token: :invalid do
|
308
|
-
it 'does not allow access if passed block evaluates to false' do
|
309
|
-
get :index, access_token: token_string
|
310
|
-
expect(response.status).to eq 401
|
311
|
-
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
312
|
-
end
|
313
|
-
|
314
|
-
it 'allows access if passed block evaluates to true' do
|
315
|
-
get :show, id: 3, access_token: token_string
|
316
|
-
expect(response).to be_success
|
317
|
-
end
|
158
|
+
context 'defined for all actions' do
|
159
|
+
controller {}
|
160
|
+
|
161
|
+
it 'it renders a custom JSON response', token: :invalid do
|
162
|
+
expect do
|
163
|
+
controller.class.doorkeeper_for
|
164
|
+
end.to raise_error(
|
165
|
+
Doorkeeper::Errors::DoorkeeperError,
|
166
|
+
/`doorkeeper_for` no longer available/
|
167
|
+
)
|
318
168
|
end
|
319
169
|
end
|
320
170
|
end
|
@@ -18,20 +18,26 @@ describe Doorkeeper::TokensController do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'when authorization has failed' do
|
21
|
-
|
22
|
-
double(:token, authorize: false)
|
23
|
-
end
|
24
|
-
|
25
|
-
before do
|
21
|
+
it 'returns the error response' do
|
22
|
+
token = double(:token, authorize: false)
|
26
23
|
allow(controller).to receive(:token) { token }
|
27
|
-
end
|
28
24
|
|
29
|
-
it 'returns the error response' do
|
30
|
-
skip 'verify need of these specs'
|
31
|
-
allow(token).to receive(:error_response).and_return(double(to_json: [], status: :unauthorized))
|
32
25
|
post :create
|
26
|
+
|
33
27
|
expect(response.status).to eq 401
|
34
28
|
expect(response.headers['WWW-Authenticate']).to match(/Bearer/)
|
35
29
|
end
|
36
30
|
end
|
31
|
+
|
32
|
+
describe 'when revoke authorization has failed' do
|
33
|
+
# http://tools.ietf.org/html/rfc7009#section-2.2
|
34
|
+
it 'returns no error response' do
|
35
|
+
token = double(:token, authorize: false)
|
36
|
+
allow(controller).to receive(:token) { token }
|
37
|
+
|
38
|
+
post :revoke
|
39
|
+
|
40
|
+
expect(response.status).to eq 200
|
41
|
+
end
|
42
|
+
end
|
37
43
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class FullProtectedResourcesController < ApplicationController
|
2
|
-
|
3
|
-
|
2
|
+
before_filter -> { doorkeeper_authorize! :admin }, only: :show
|
3
|
+
before_filter :doorkeeper_authorize!, only: :index
|
4
4
|
|
5
5
|
def index
|
6
6
|
render text: 'index'
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class MetalController < ActionController::Metal
|
2
2
|
include AbstractController::Callbacks
|
3
3
|
include ActionController::Head
|
4
|
-
include Doorkeeper::Helpers
|
4
|
+
include Doorkeeper::Rails::Helpers
|
5
5
|
|
6
|
-
|
6
|
+
before_filter :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
|
-
|
2
|
+
before_filter :doorkeeper_authorize!, only: :index
|
3
3
|
|
4
4
|
def index
|
5
5
|
render text: 'protected index'
|
6
6
|
end
|
7
7
|
|
8
8
|
def show
|
9
|
-
render text: 'protected show'
|
9
|
+
render text: 'non protected show'
|
10
10
|
end
|
11
11
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
case DOORKEEPER_ORM
|
2
|
-
when
|
1
|
+
case DOORKEEPER_ORM.to_s
|
2
|
+
when "active_record"
|
3
3
|
class User < ActiveRecord::Base
|
4
4
|
end
|
5
|
-
when
|
5
|
+
when /mongoid/
|
6
6
|
class User
|
7
7
|
include Mongoid::Document
|
8
8
|
include Mongoid::Timestamps
|
@@ -10,7 +10,7 @@ when :mongoid2, :mongoid3, :mongoid4
|
|
10
10
|
field :name, type: String
|
11
11
|
field :password, type: String
|
12
12
|
end
|
13
|
-
when
|
13
|
+
when "mongo_mapper"
|
14
14
|
class User
|
15
15
|
include MongoMapper::Document
|
16
16
|
timestamps!
|
@@ -21,7 +21,7 @@ when :mongo_mapper
|
|
21
21
|
end
|
22
22
|
|
23
23
|
class User
|
24
|
-
if ::Rails.version.to_i < 4
|
24
|
+
if ::Rails.version.to_i < 4 || defined?(::ProtectedAttributes)
|
25
25
|
attr_accessible :name, :password
|
26
26
|
end
|
27
27
|
|
@@ -5,7 +5,7 @@ require 'sprockets/railtie'
|
|
5
5
|
|
6
6
|
Bundler.require :default
|
7
7
|
|
8
|
-
orm = if
|
8
|
+
orm = if DOORKEEPER_ORM =~ /mongoid/
|
9
9
|
Mongoid.load!(File.join(File.dirname(File.expand_path(__FILE__)), "#{DOORKEEPER_ORM}.yml"))
|
10
10
|
:mongoid
|
11
11
|
else
|
@@ -50,5 +50,7 @@ module Dummy
|
|
50
50
|
|
51
51
|
# Version of your assets, change this if you want to expire all your assets
|
52
52
|
config.assets.version = '1.0'
|
53
|
+
|
54
|
+
I18n.enforce_available_locales = false
|
53
55
|
end
|
54
56
|
end
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
3
|
|
4
|
-
|
4
|
+
orm = ENV['BUNDLE_GEMFILE'].match(/Gemfile\.(.+)\.rb/)
|
5
|
+
unless defined?(DOORKEEPER_ORM)
|
6
|
+
DOORKEEPER_ORM = (orm && orm[1]) || :active_record
|
7
|
+
end
|
5
8
|
|
6
9
|
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
|
Binary file
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -9,57 +9,58 @@
|
|
9
9
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
10
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
11
|
#
|
12
|
-
# It's strongly recommended
|
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: 20141209001746) do
|
15
15
|
|
16
|
-
create_table
|
17
|
-
t.integer
|
18
|
-
t.integer
|
19
|
-
t.string
|
20
|
-
t.integer
|
21
|
-
t.
|
22
|
-
t.datetime
|
23
|
-
t.datetime
|
24
|
-
t.string
|
16
|
+
create_table "oauth_access_grants", force: true 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.string "redirect_uri", limit: 2048, null: false
|
22
|
+
t.datetime "created_at", null: false
|
23
|
+
t.datetime "revoked_at"
|
24
|
+
t.string "scopes"
|
25
25
|
end
|
26
26
|
|
27
|
-
add_index
|
27
|
+
add_index "oauth_access_grants", ["token"], name: "index_oauth_access_grants_on_token", unique: true
|
28
28
|
|
29
|
-
create_table
|
30
|
-
t.integer
|
31
|
-
t.integer
|
32
|
-
t.string
|
33
|
-
t.string
|
34
|
-
t.integer
|
35
|
-
t.datetime
|
36
|
-
t.datetime
|
37
|
-
t.string
|
29
|
+
create_table "oauth_access_tokens", force: true do |t|
|
30
|
+
t.integer "resource_owner_id"
|
31
|
+
t.integer "application_id"
|
32
|
+
t.string "token", null: false
|
33
|
+
t.string "refresh_token"
|
34
|
+
t.integer "expires_in"
|
35
|
+
t.datetime "revoked_at"
|
36
|
+
t.datetime "created_at", null: false
|
37
|
+
t.string "scopes"
|
38
38
|
end
|
39
39
|
|
40
|
-
add_index
|
41
|
-
add_index
|
42
|
-
add_index
|
40
|
+
add_index "oauth_access_tokens", ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true
|
41
|
+
add_index "oauth_access_tokens", ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id"
|
42
|
+
add_index "oauth_access_tokens", ["token"], name: "index_oauth_access_tokens_on_token", unique: true
|
43
43
|
|
44
|
-
create_table
|
45
|
-
t.string
|
46
|
-
t.string
|
47
|
-
t.string
|
48
|
-
t.
|
49
|
-
t.datetime
|
50
|
-
t.datetime
|
51
|
-
t.integer
|
52
|
-
t.string
|
44
|
+
create_table "oauth_applications", force: true do |t|
|
45
|
+
t.string "name", null: false
|
46
|
+
t.string "uid", null: false
|
47
|
+
t.string "secret", null: false
|
48
|
+
t.string "redirect_uri", limit: 2048, null: false
|
49
|
+
t.datetime "created_at", null: false
|
50
|
+
t.datetime "updated_at", null: false
|
51
|
+
t.integer "owner_id"
|
52
|
+
t.string "owner_type"
|
53
|
+
t.string "scopes", default: "", null: false
|
53
54
|
end
|
54
55
|
|
55
|
-
add_index
|
56
|
-
add_index
|
56
|
+
add_index "oauth_applications", ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type"
|
57
|
+
add_index "oauth_applications", ["uid"], name: "index_oauth_applications_on_uid", unique: true
|
57
58
|
|
58
|
-
create_table
|
59
|
-
t.string
|
60
|
-
t.datetime
|
61
|
-
t.datetime
|
62
|
-
t.string
|
59
|
+
create_table "users", force: true do |t|
|
60
|
+
t.string "name"
|
61
|
+
t.datetime "created_at", null: false
|
62
|
+
t.datetime "updated_at", null: false
|
63
|
+
t.string "password"
|
63
64
|
end
|
64
65
|
|
65
66
|
end
|
data/spec/factories.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :access_grant, class: Doorkeeper::AccessGrant do
|
3
|
+
sequence(:resource_owner_id) { |n| n }
|
4
|
+
application
|
5
|
+
redirect_uri 'https://app.com/callback'
|
6
|
+
expires_in 100
|
7
|
+
scopes 'public write'
|
8
|
+
end
|
9
|
+
|
10
|
+
factory :access_token, class: Doorkeeper::AccessToken do
|
11
|
+
sequence(:resource_owner_id) { |n| n }
|
12
|
+
application
|
13
|
+
expires_in 2.hours
|
14
|
+
|
15
|
+
factory :clientless_access_token do
|
16
|
+
application nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
factory :application, class: Doorkeeper::Application do
|
21
|
+
sequence(:name) { |n| "Application #{n}" }
|
22
|
+
redirect_uri 'https://app.com/callback'
|
23
|
+
end
|
24
|
+
end
|