doorkeeper 3.1.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.

Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -10
  3. data/CONTRIBUTING.md +2 -0
  4. data/Gemfile +8 -4
  5. data/NEWS.md +57 -2
  6. data/README.md +48 -40
  7. data/Rakefile +1 -1
  8. data/app/controllers/doorkeeper/application_metal_controller.rb +1 -2
  9. data/app/controllers/doorkeeper/applications_controller.rb +2 -2
  10. data/app/controllers/doorkeeper/authorizations_controller.rb +1 -1
  11. data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
  12. data/app/controllers/doorkeeper/tokens_controller.rb +1 -1
  13. data/app/helpers/doorkeeper/dashboard_helper.rb +13 -11
  14. data/app/views/doorkeeper/applications/show.html.erb +1 -1
  15. data/app/views/layouts/doorkeeper/admin.html.erb +1 -1
  16. data/config/locales/en.yml +1 -0
  17. data/doorkeeper.gemspec +7 -6
  18. data/lib/doorkeeper/config.rb +10 -15
  19. data/lib/doorkeeper/engine.rb +11 -7
  20. data/lib/doorkeeper/helpers/controller.rb +1 -1
  21. data/lib/doorkeeper/models/access_grant_mixin.rb +9 -5
  22. data/lib/doorkeeper/models/access_token_mixin.rb +28 -22
  23. data/lib/doorkeeper/models/application_mixin.rb +3 -7
  24. data/lib/doorkeeper/models/concerns/expirable.rb +2 -2
  25. data/lib/doorkeeper/models/concerns/ownership.rb +6 -1
  26. data/lib/doorkeeper/models/concerns/revocable.rb +19 -2
  27. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
  28. data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
  29. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +2 -1
  30. data/lib/doorkeeper/oauth/client_credentials_request.rb +7 -4
  31. data/lib/doorkeeper/oauth/code_response.rb +13 -14
  32. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
  33. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +2 -1
  34. data/lib/doorkeeper/oauth/password_access_token_request.rb +6 -10
  35. data/lib/doorkeeper/oauth/refresh_token_request.rb +23 -11
  36. data/lib/doorkeeper/oauth/scopes.rb +2 -2
  37. data/lib/doorkeeper/oauth/token.rb +6 -5
  38. data/lib/doorkeeper/oauth/token_response.rb +1 -1
  39. data/lib/doorkeeper/orm/active_record/access_token.rb +8 -0
  40. data/lib/doorkeeper/orm/active_record/application.rb +2 -7
  41. data/lib/doorkeeper/orm/active_record.rb +0 -16
  42. data/lib/doorkeeper/rails/helpers.rb +1 -1
  43. data/lib/doorkeeper/rails/routes/mapper.rb +1 -1
  44. data/lib/doorkeeper/rails/routes.rb +2 -1
  45. data/lib/doorkeeper/request/password.rb +11 -1
  46. data/lib/doorkeeper/version.rb +1 -1
  47. data/lib/doorkeeper.rb +1 -1
  48. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -0
  49. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +1 -1
  50. data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb +11 -0
  51. data/lib/generators/doorkeeper/templates/initializer.rb +2 -2
  52. data/lib/generators/doorkeeper/templates/migration.rb +23 -5
  53. data/spec/controllers/authorizations_controller_spec.rb +0 -14
  54. data/spec/controllers/protected_resources_controller_spec.rb +47 -18
  55. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -4
  56. data/spec/dummy/app/controllers/home_controller.rb +1 -1
  57. data/spec/dummy/app/controllers/metal_controller.rb +1 -1
  58. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +3 -3
  59. data/spec/dummy/app/models/user.rb +0 -4
  60. data/spec/dummy/config/application.rb +2 -36
  61. data/spec/dummy/config/environment.rb +1 -1
  62. data/spec/dummy/config/environments/test.rb +4 -15
  63. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +6 -0
  64. data/spec/dummy/config/initializers/doorkeeper.rb +2 -2
  65. data/spec/dummy/db/migrate/{20130902165751_create_doorkeeper_tables.rb → 20151223192035_create_doorkeeper_tables.rb} +24 -5
  66. data/spec/dummy/db/migrate/{20130902175349_add_owner_to_application.rb → 20151223200000_add_owner_to_application.rb} +0 -0
  67. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +11 -0
  68. data/spec/dummy/db/schema.rb +23 -22
  69. data/spec/lib/config_spec.rb +2 -2
  70. data/spec/lib/models/revocable_spec.rb +27 -4
  71. data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
  72. data/spec/lib/oauth/code_response_spec.rb +34 -0
  73. data/spec/lib/oauth/password_access_token_request_spec.rb +5 -5
  74. data/spec/lib/oauth/refresh_token_request_spec.rb +34 -3
  75. data/spec/lib/oauth/scopes_spec.rb +0 -1
  76. data/spec/lib/oauth/token_spec.rb +12 -5
  77. data/spec/models/doorkeeper/access_token_spec.rb +45 -1
  78. data/spec/models/doorkeeper/application_spec.rb +2 -10
  79. data/spec/requests/flows/password_spec.rb +26 -5
  80. data/spec/requests/flows/refresh_token_spec.rb +87 -17
  81. data/spec/spec_helper_integration.rb +3 -0
  82. data/spec/support/helpers/model_helper.rb +27 -5
  83. data/spec/support/http_method_shim.rb +24 -0
  84. data/spec/support/shared/controllers_shared_context.rb +13 -4
  85. data/spec/support/shared/models_shared_examples.rb +1 -1
  86. metadata +52 -32
  87. data/lib/generators/doorkeeper/application_scopes_generator.rb +0 -34
  88. data/lib/generators/doorkeeper/templates/add_scopes_to_oauth_applications.rb +0 -5
  89. data/spec/dummy/db/migrate/20141209001746_add_scopes_to_oauth_applications.rb +0 -5
@@ -41,10 +41,10 @@ Doorkeeper.configure do
41
41
  # use_refresh_token
42
42
 
43
43
  # Provide support for an owner to be assigned to each registered application (disabled by default)
44
- # Optional parameter :confirmation => true (default false) if you want to enforce ownership of
44
+ # Optional parameter confirmation: true (default false) if you want to enforce ownership of
45
45
  # a registered application
46
46
  # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
47
- # enable_application_owner :confirmation => false
47
+ # enable_application_owner confirmation: false
48
48
 
49
49
  # Define access token scopes for your provider
50
50
  # For more information go to
@@ -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
@@ -89,16 +89,6 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
89
89
  it 'returns the existing access token in a fragment'
90
90
  end
91
91
 
92
- describe 'GET #new' do
93
- before do
94
- get :new, client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri
95
- end
96
-
97
- it 'renders new template' do
98
- expect(response).to render_template(:new)
99
- end
100
- end
101
-
102
92
  describe 'GET #new token request with native url and skip_authorization true' do
103
93
  before do
104
94
  allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
@@ -191,10 +181,6 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
191
181
  expect(response).to_not be_redirect
192
182
  end
193
183
 
194
- it 'renders error template' do
195
- expect(response).to render_template(:error)
196
- end
197
-
198
184
  it 'does not issue any token' do
199
185
  expect(Doorkeeper::AccessGrant.count).to eq 0
200
186
  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
@@ -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
@@ -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: 20141209001746) do
14
+ ActiveRecord::Schema.define(version: 20160320211015) do
15
15
 
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
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: true do |t|
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", null: false
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", null: false
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: 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
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: true do |t|
60
+ create_table "users", force: :cascade do |t|
60
61
  t.string "name"
61
- t.datetime "created_at", null: false
62
- t.datetime "updated_at", null: false
62
+ t.datetime "created_at"
63
+ t.datetime "updated_at"
63
64
  t.string "password"
64
65
  end
65
66
 
@@ -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 &block
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 'access_token_credentials' do
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