doorkeeper 5.1.0.rc2 → 5.1.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 (208) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +2 -1
  3. data/.rubocop.yml +37 -4
  4. data/.travis.yml +4 -27
  5. data/Appraisals +8 -12
  6. data/Gemfile +6 -2
  7. data/NEWS.md +16 -0
  8. data/README.md +11 -2
  9. data/Rakefile +10 -8
  10. data/app/controllers/doorkeeper/application_controller.rb +1 -2
  11. data/app/controllers/doorkeeper/application_metal_controller.rb +2 -13
  12. data/app/controllers/doorkeeper/applications_controller.rb +17 -5
  13. data/app/controllers/doorkeeper/token_info_controller.rb +1 -1
  14. data/app/controllers/doorkeeper/tokens_controller.rb +7 -7
  15. data/app/helpers/doorkeeper/dashboard_helper.rb +1 -1
  16. data/app/validators/redirect_uri_validator.rb +5 -2
  17. data/app/views/doorkeeper/applications/_form.html.erb +6 -0
  18. data/bin/console +5 -4
  19. data/config/locales/en.yml +1 -0
  20. data/doorkeeper.gemspec +24 -22
  21. data/gemfiles/rails_5_0.gemfile +2 -1
  22. data/gemfiles/rails_5_1.gemfile +2 -1
  23. data/gemfiles/rails_5_2.gemfile +2 -1
  24. data/gemfiles/rails_6_0.gemfile +1 -0
  25. data/gemfiles/rails_master.gemfile +1 -0
  26. data/lib/doorkeeper.rb +68 -66
  27. data/lib/doorkeeper/config.rb +53 -90
  28. data/lib/doorkeeper/config/option.rb +64 -0
  29. data/lib/doorkeeper/engine.rb +1 -1
  30. data/lib/doorkeeper/grape/authorization_decorator.rb +4 -4
  31. data/lib/doorkeeper/grape/helpers.rb +3 -3
  32. data/lib/doorkeeper/helpers/controller.rb +1 -1
  33. data/lib/doorkeeper/models/access_grant_mixin.rb +4 -2
  34. data/lib/doorkeeper/models/access_token_mixin.rb +10 -10
  35. data/lib/doorkeeper/models/application_mixin.rb +1 -0
  36. data/lib/doorkeeper/models/concerns/expirable.rb +1 -0
  37. data/lib/doorkeeper/models/concerns/ownership.rb +1 -6
  38. data/lib/doorkeeper/models/concerns/revocable.rb +2 -1
  39. data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
  40. data/lib/doorkeeper/models/concerns/secret_storable.rb +2 -0
  41. data/lib/doorkeeper/oauth.rb +5 -5
  42. data/lib/doorkeeper/oauth/authorization/code.rb +1 -1
  43. data/lib/doorkeeper/oauth/authorization/token.rb +9 -6
  44. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
  45. data/lib/doorkeeper/oauth/authorization_code_request.rb +5 -3
  46. data/lib/doorkeeper/oauth/client_credentials/validation.rb +1 -1
  47. data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
  48. data/lib/doorkeeper/oauth/error_response.rb +5 -5
  49. data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
  50. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
  51. data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -1
  52. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +6 -2
  53. data/lib/doorkeeper/oauth/invalid_token_response.rb +1 -1
  54. data/lib/doorkeeper/oauth/pre_authorization.rb +4 -3
  55. data/lib/doorkeeper/oauth/refresh_token_request.rb +1 -1
  56. data/lib/doorkeeper/oauth/scopes.rb +5 -3
  57. data/lib/doorkeeper/oauth/token.rb +2 -2
  58. data/lib/doorkeeper/oauth/token_introspection.rb +4 -4
  59. data/lib/doorkeeper/oauth/token_response.rb +9 -9
  60. data/lib/doorkeeper/orm/active_record.rb +6 -6
  61. data/lib/doorkeeper/orm/active_record/access_grant.rb +5 -12
  62. data/lib/doorkeeper/orm/active_record/access_token.rb +6 -13
  63. data/lib/doorkeeper/orm/active_record/application.rb +6 -5
  64. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +10 -3
  65. data/lib/doorkeeper/rails/helpers.rb +1 -1
  66. data/lib/doorkeeper/rails/routes.rb +11 -11
  67. data/lib/doorkeeper/rails/routes/mapping.rb +7 -7
  68. data/lib/doorkeeper/rake.rb +1 -1
  69. data/lib/doorkeeper/rake/db.rake +13 -13
  70. data/lib/doorkeeper/request.rb +1 -1
  71. data/lib/doorkeeper/secret_storing/base.rb +7 -6
  72. data/lib/doorkeeper/secret_storing/bcrypt.rb +4 -3
  73. data/lib/doorkeeper/secret_storing/plain.rb +4 -4
  74. data/lib/doorkeeper/secret_storing/sha256_hash.rb +3 -2
  75. data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
  76. data/lib/doorkeeper/version.rb +2 -2
  77. data/lib/generators/doorkeeper/application_owner_generator.rb +10 -9
  78. data/lib/generators/doorkeeper/confidential_applications_generator.rb +10 -9
  79. data/lib/generators/doorkeeper/install_generator.rb +11 -9
  80. data/lib/generators/doorkeeper/migration_generator.rb +9 -9
  81. data/lib/generators/doorkeeper/pkce_generator.rb +10 -9
  82. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +10 -9
  83. data/lib/generators/doorkeeper/templates/initializer.rb +30 -5
  84. data/lib/generators/doorkeeper/templates/migration.rb.erb +15 -7
  85. data/lib/generators/doorkeeper/views_generator.rb +6 -4
  86. data/spec/controllers/application_metal_controller_spec.rb +10 -10
  87. data/spec/controllers/applications_controller_spec.rb +54 -52
  88. data/spec/controllers/authorizations_controller_spec.rb +136 -142
  89. data/spec/controllers/protected_resources_controller_spec.rb +78 -76
  90. data/spec/controllers/token_info_controller_spec.rb +13 -11
  91. data/spec/controllers/tokens_controller_spec.rb +109 -94
  92. data/spec/dummy/Rakefile +3 -1
  93. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  94. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -0
  95. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -2
  96. data/spec/dummy/app/controllers/home_controller.rb +5 -3
  97. data/spec/dummy/app/controllers/metal_controller.rb +2 -0
  98. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +4 -2
  99. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  100. data/spec/dummy/app/models/user.rb +2 -0
  101. data/spec/dummy/config.ru +3 -1
  102. data/spec/dummy/config/application.rb +13 -0
  103. data/spec/dummy/config/environments/development.rb +2 -0
  104. data/spec/dummy/config/environments/production.rb +2 -0
  105. data/spec/dummy/config/environments/test.rb +3 -1
  106. data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
  107. data/spec/dummy/config/initializers/doorkeeper.rb +5 -2
  108. data/spec/dummy/config/initializers/secret_token.rb +3 -1
  109. data/spec/dummy/config/initializers/session_store.rb +3 -1
  110. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  111. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +17 -10
  112. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +2 -0
  113. data/spec/dummy/db/schema.rb +1 -1
  114. data/spec/dummy/script/rails +5 -3
  115. data/spec/factories.rb +5 -3
  116. data/spec/generators/application_owner_generator_spec.rb +13 -26
  117. data/spec/generators/confidential_applications_generator_spec.rb +12 -28
  118. data/spec/generators/install_generator_spec.rb +17 -15
  119. data/spec/generators/migration_generator_spec.rb +13 -26
  120. data/spec/generators/pkce_generator_spec.rb +11 -26
  121. data/spec/generators/previous_refresh_token_generator_spec.rb +16 -29
  122. data/spec/generators/templates/routes.rb +2 -0
  123. data/spec/generators/views_generator_spec.rb +14 -12
  124. data/spec/grape/grape_integration_spec.rb +34 -32
  125. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +9 -7
  126. data/spec/lib/config_spec.rb +137 -136
  127. data/spec/lib/doorkeeper_spec.rb +3 -1
  128. data/spec/lib/models/expirable_spec.rb +12 -10
  129. data/spec/lib/models/reusable_spec.rb +6 -6
  130. data/spec/lib/models/revocable_spec.rb +8 -6
  131. data/spec/lib/models/scopes_spec.rb +19 -17
  132. data/spec/lib/models/secret_storable_spec.rb +71 -49
  133. data/spec/lib/oauth/authorization/uri_builder_spec.rb +17 -15
  134. data/spec/lib/oauth/authorization_code_request_spec.rb +18 -12
  135. data/spec/lib/oauth/base_request_spec.rb +20 -8
  136. data/spec/lib/oauth/base_response_spec.rb +3 -1
  137. data/spec/lib/oauth/client/credentials_spec.rb +24 -22
  138. data/spec/lib/oauth/client_credentials/creator_spec.rb +13 -11
  139. data/spec/lib/oauth/client_credentials/issuer_spec.rb +27 -18
  140. data/spec/lib/oauth/client_credentials/validation_spec.rb +17 -15
  141. data/spec/lib/oauth/client_credentials_integration_spec.rb +7 -5
  142. data/spec/lib/oauth/client_credentials_request_spec.rb +27 -21
  143. data/spec/lib/oauth/client_spec.rb +15 -13
  144. data/spec/lib/oauth/code_request_spec.rb +8 -6
  145. data/spec/lib/oauth/code_response_spec.rb +9 -7
  146. data/spec/lib/oauth/error_response_spec.rb +14 -12
  147. data/spec/lib/oauth/error_spec.rb +4 -2
  148. data/spec/lib/oauth/forbidden_token_response_spec.rb +7 -5
  149. data/spec/lib/oauth/helpers/scope_checker_spec.rb +35 -33
  150. data/spec/lib/oauth/helpers/unique_token_spec.rb +8 -6
  151. data/spec/lib/oauth/helpers/uri_checker_spec.rb +103 -101
  152. data/spec/lib/oauth/invalid_token_response_spec.rb +3 -1
  153. data/spec/lib/oauth/password_access_token_request_spec.rb +52 -34
  154. data/spec/lib/oauth/pre_authorization_spec.rb +64 -62
  155. data/spec/lib/oauth/refresh_token_request_spec.rb +36 -33
  156. data/spec/lib/oauth/scopes_spec.rb +63 -61
  157. data/spec/lib/oauth/token_request_spec.rb +66 -26
  158. data/spec/lib/oauth/token_response_spec.rb +39 -37
  159. data/spec/lib/oauth/token_spec.rb +51 -49
  160. data/spec/lib/request/strategy_spec.rb +3 -1
  161. data/spec/lib/secret_storing/base_spec.rb +23 -23
  162. data/spec/lib/secret_storing/bcrypt_spec.rb +18 -18
  163. data/spec/lib/secret_storing/plain_spec.rb +17 -17
  164. data/spec/lib/secret_storing/sha256_hash_spec.rb +16 -16
  165. data/spec/lib/server_spec.rb +16 -14
  166. data/spec/lib/stale_records_cleaner_spec.rb +17 -17
  167. data/spec/models/doorkeeper/access_grant_spec.rb +30 -26
  168. data/spec/models/doorkeeper/access_token_spec.rb +97 -95
  169. data/spec/models/doorkeeper/application_spec.rb +98 -57
  170. data/spec/requests/applications/applications_request_spec.rb +98 -66
  171. data/spec/requests/applications/authorized_applications_spec.rb +20 -18
  172. data/spec/requests/endpoints/authorization_spec.rb +25 -23
  173. data/spec/requests/endpoints/token_spec.rb +38 -36
  174. data/spec/requests/flows/authorization_code_errors_spec.rb +26 -24
  175. data/spec/requests/flows/authorization_code_spec.rb +161 -159
  176. data/spec/requests/flows/client_credentials_spec.rb +53 -51
  177. data/spec/requests/flows/implicit_grant_errors_spec.rb +10 -8
  178. data/spec/requests/flows/implicit_grant_spec.rb +27 -25
  179. data/spec/requests/flows/password_spec.rb +56 -54
  180. data/spec/requests/flows/refresh_token_spec.rb +45 -43
  181. data/spec/requests/flows/revoke_token_spec.rb +29 -27
  182. data/spec/requests/flows/skip_authorization_spec.rb +23 -21
  183. data/spec/requests/protected_resources/metal_spec.rb +7 -5
  184. data/spec/requests/protected_resources/private_api_spec.rb +35 -33
  185. data/spec/routing/custom_controller_routes_spec.rb +67 -65
  186. data/spec/routing/default_routes_spec.rb +22 -20
  187. data/spec/routing/scoped_routes_spec.rb +20 -18
  188. data/spec/spec_helper.rb +14 -13
  189. data/spec/spec_helper_integration.rb +3 -1
  190. data/spec/support/dependencies/factory_bot.rb +3 -1
  191. data/spec/support/doorkeeper_rspec.rb +3 -1
  192. data/spec/support/helpers/access_token_request_helper.rb +3 -1
  193. data/spec/support/helpers/authorization_request_helper.rb +4 -2
  194. data/spec/support/helpers/config_helper.rb +2 -0
  195. data/spec/support/helpers/model_helper.rb +3 -1
  196. data/spec/support/helpers/request_spec_helper.rb +5 -3
  197. data/spec/support/helpers/url_helper.rb +9 -7
  198. data/spec/support/http_method_shim.rb +4 -9
  199. data/spec/support/orm/active_record.rb +3 -1
  200. data/spec/support/shared/controllers_shared_context.rb +18 -16
  201. data/spec/support/shared/hashing_shared_context.rb +3 -3
  202. data/spec/support/shared/models_shared_examples.rb +12 -10
  203. data/spec/validators/redirect_uri_validator_spec.rb +74 -45
  204. data/spec/version/version_spec.rb +7 -5
  205. metadata +12 -16
  206. data/gemfiles/rails_4_2.gemfile +0 -17
  207. data/spec/dummy/config/initializers/new_framework_defaults.rb +0 -8
  208. data/spec/support/ruby_2_6_rails_4_2_patch.rb +0 -14
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  # Add your own tasks in files placed in lib/tasks ending in .rake,
3
5
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
6
 
5
- require File.expand_path('config/application', __dir__)
7
+ require File.expand_path("config/application", __dir__)
6
8
 
7
9
  Dummy::Application.load_tasks
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ApplicationController < ActionController::Base
2
4
  protect_from_forgery with: :exception
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CustomAuthorizationsController < ::ApplicationController
2
4
  %w[index show new create edit update destroy].each do |action|
3
5
  define_method action do
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class FullProtectedResourcesController < ApplicationController
2
4
  before_action -> { doorkeeper_authorize! :write, :admin }, only: :show
3
5
  before_action :doorkeeper_authorize!, only: :index
4
6
 
5
7
  def index
6
- render plain: 'index'
8
+ render plain: "index"
7
9
  end
8
10
 
9
11
  def show
10
- render plain: 'show'
12
+ render plain: "show"
11
13
  end
12
14
  end
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class HomeController < ApplicationController
2
4
  def index; end
3
5
 
4
6
  def sign_in
5
7
  session[:user_id] = if Rails.env.development?
6
- User.first || User.create!(name: 'Joe', password: 'sekret')
8
+ User.first || User.create!(name: "Joe", password: "sekret")
7
9
  else
8
10
  User.first
9
11
  end
10
- redirect_to '/'
12
+ redirect_to "/"
11
13
  end
12
14
 
13
15
  def callback
14
- render plain: 'ok'
16
+ render plain: "ok"
15
17
  end
16
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MetalController < ActionController::Metal
2
4
  include AbstractController::Callbacks
3
5
  include ActionController::Head
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class SemiProtectedResourcesController < ApplicationController
2
4
  before_action :doorkeeper_authorize!, only: :index
3
5
 
4
6
  def index
5
- render plain: 'protected index'
7
+ render plain: "protected index"
6
8
  end
7
9
 
8
10
  def show
9
- render plain: 'non protected show'
11
+ render plain: "non protected show"
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ApplicationHelper
2
4
  def current_user
3
5
  @current_user ||= User.find_by_id(session[:user_id])
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class User < ActiveRecord::Base
2
4
  def self.authenticate!(name, password)
3
5
  User.where(name: name, password: password).first
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is used by Rack-based servers to start the application.
2
4
 
3
- require ::File.expand_path('../config/environment', __FILE__)
5
+ require ::File.expand_path("../config/environment", __FILE__)
4
6
  run Dummy::Application
@@ -27,6 +27,19 @@ require "#{orm}/railtie"
27
27
 
28
28
  module Dummy
29
29
  class Application < Rails::Application
30
+ if Rails.gem_version < Gem::Version.new('5.1')
31
+ config.action_controller.per_form_csrf_tokens = true
32
+ config.action_controller.forgery_protection_origin_check = true
33
+
34
+ ActiveSupport.to_time_preserves_timezone = true
35
+
36
+ config.active_record.belongs_to_required_by_default = true
37
+
38
+ config.ssl_options = { hsts: { subdomains: true } }
39
+ else
40
+ config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
41
+ end
42
+
30
43
  # Settings in config/environments/* take precedence over those specified here.
31
44
  # Application configuration should go into files in config/initializers
32
45
  # -- all .rb files in that directory are automatically loaded.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -8,7 +10,7 @@ Dummy::Application.configure do
8
10
  config.cache_classes = true
9
11
 
10
12
  config.assets.enabled = true
11
- config.assets.version = '1.0'
13
+ config.assets.version = "1.0"
12
14
  config.assets.digest = false
13
15
 
14
16
  # Do not eager load code on boot. This avoids loading your whole application
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Doorkeeper.configure do
2
4
  # Change the ORM that doorkeeper will use.
3
5
  orm DOORKEEPER_ORM
@@ -5,7 +7,7 @@ Doorkeeper.configure do
5
7
  # This block will be called to check whether the resource owner is authenticated or not.
6
8
  resource_owner_authenticator do
7
9
  # Put your resource owner authentication logic here.
8
- User.where(id: session[:user_id]).first || redirect_to(root_url, alert: 'Needs sign in.')
10
+ User.where(id: session[:user_id]).first || redirect_to(root_url, alert: "Needs sign in.")
9
11
  end
10
12
 
11
13
  # If you didn't skip applications controller from Doorkeeper routes in your application routes.rb
@@ -66,7 +68,8 @@ Doorkeeper.configure do
66
68
  # Change the native redirect uri for client apps
67
69
  # When clients register with the following redirect uri, they won't be redirected to any server and
68
70
  # the authorization code will be displayed within the provider
69
- # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
71
+ # The value can be any string. Use nil to disable this feature.
72
+ # When disabled, clients must provide a valid URL
70
73
  # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
71
74
  #
72
75
  # native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # Your secret key for verifying the integrity of signed cookies.
@@ -5,4 +7,4 @@
5
7
  # Make sure the secret is at least 30 characters and all random,
6
8
  # no regular words or you'll be exposed to dictionary attacks.
7
9
  Dummy::Application.config.secret_key_base =
8
- 'c00157b5a1bb6181792f0f4a8a080485de7bab9987e6cf159'
10
+ "c00157b5a1bb6181792f0f4a8a080485de7bab9987e6cf159"
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
- Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
5
+ Dummy::Application.config.session_store :cookie_store, key: "_dummy_session"
4
6
 
5
7
  # Use the database for sessions instead of the cookie-based default,
6
8
  # which shouldn't be used to store highly confidential information
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
  #
3
5
  # This file contains settings for ActionController::ParamsWrapper which
@@ -3,18 +3,22 @@
3
3
  class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
4
4
  def change
5
5
  create_table :oauth_applications do |t|
6
- t.string :name, null: false
7
- t.string :uid, null: false
8
- t.string :secret, null: false
6
+ t.string :name, null: false
7
+ t.string :uid, null: false
8
+ t.string :secret, null: false
9
+
10
+ # Remove `null: false` if you are planning to use grant flows
11
+ # that doesn't require redirect URI to be used during authorization
12
+ # like Client Credentials flow or Resource Owner Password.
9
13
  t.text :redirect_uri, null: false
10
- t.string :scopes, null: false, default: ''
14
+ t.string :scopes, null: false, default: ""
11
15
  t.timestamps null: false
12
16
  end
13
17
 
14
18
  add_index :oauth_applications, :uid, unique: true
15
19
 
16
20
  create_table :oauth_access_grants do |t|
17
- t.integer :resource_owner_id, null: false
21
+ t.references :resource_owner, null: false
18
22
  t.references :application, null: false
19
23
  t.string :token, null: false
20
24
  t.integer :expires_in, null: false
@@ -32,16 +36,16 @@ class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
32
36
  )
33
37
 
34
38
  create_table :oauth_access_tokens do |t|
35
- t.integer :resource_owner_id
36
- t.references :application
39
+ t.references :resource_owner, index: true
40
+ t.references :application, null: false
37
41
 
38
42
  # If you use a custom token generator you may need to change this column
39
43
  # from string to text, so that it accepts tokens larger than 255
40
44
  # characters. More info on custom token generators in:
41
45
  # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
42
46
  #
43
- # t.text :token, null: false
44
- t.string :token, null: false
47
+ # t.text :token, null: false
48
+ t.string :token, null: false
45
49
 
46
50
  t.string :refresh_token
47
51
  t.integer :expires_in
@@ -51,12 +55,15 @@ class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
51
55
  end
52
56
 
53
57
  add_index :oauth_access_tokens, :token, unique: true
54
- add_index :oauth_access_tokens, :resource_owner_id
55
58
  add_index :oauth_access_tokens, :refresh_token, unique: true
56
59
  add_foreign_key(
57
60
  :oauth_access_tokens,
58
61
  :oauth_applications,
59
62
  column: :application_id
60
63
  )
64
+
65
+ # Uncomment below to ensure a valid reference to the resource owner's table
66
+ add_foreign_key :oauth_access_grants, :users, column: :resource_owner_id
67
+ add_foreign_key :oauth_access_tokens, :users, column: :resource_owner_id
61
68
  end
62
69
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class EnablePkce < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column :oauth_access_grants, :code_challenge, :string, null: true
@@ -47,7 +47,7 @@ ActiveRecord::Schema.define(version: 20180210183654) do
47
47
  t.string "name", null: false
48
48
  t.string "uid", null: false
49
49
  t.string "secret", null: false
50
- t.text "redirect_uri", null: false
50
+ t.text "redirect_uri"
51
51
  t.string "scopes", default: "", null: false
52
52
  t.datetime "created_at", null: false
53
53
  t.datetime "updated_at", null: false
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  # This command will automatically be run when you run "rails" with Rails 3 gems
3
5
  # installed from the root of your application.
4
6
 
5
- APP_PATH = File.expand_path('../config/application', __dir__)
6
- require File.expand_path('../config/boot', __dir__)
7
- require 'rails/commands'
7
+ APP_PATH = File.expand_path("../config/application", __dir__)
8
+ require File.expand_path("../config/boot", __dir__)
9
+ require "rails/commands"
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :access_grant, class: "Doorkeeper::AccessGrant" do
3
5
  sequence(:resource_owner_id) { |n| n }
4
6
  application
5
- redirect_uri { 'https://app.com/callback' }
7
+ redirect_uri { "https://app.com/callback" }
6
8
  expires_in { 100 }
7
- scopes { 'public write' }
9
+ scopes { "public write" }
8
10
  end
9
11
 
10
12
  factory :access_token, class: "Doorkeeper::AccessToken" do
@@ -19,7 +21,7 @@ FactoryBot.define do
19
21
 
20
22
  factory :application, class: "Doorkeeper::Application" do
21
23
  sequence(:name) { |n| "Application #{n}" }
22
- redirect_uri { 'https://app.com/callback' }
24
+ redirect_uri { "https://app.com/callback" }
23
25
  end
24
26
 
25
27
  # do not name this factory :user, otherwise it will conflict with factories
@@ -1,40 +1,27 @@
1
- require 'spec_helper'
2
- require 'generators/doorkeeper/application_owner_generator'
1
+ # frozen_string_literal: true
3
2
 
4
- describe 'Doorkeeper::ApplicationOwnerGenerator' do
3
+ require "spec_helper"
4
+ require "generators/doorkeeper/application_owner_generator"
5
+
6
+ describe "Doorkeeper::ApplicationOwnerGenerator" do
5
7
  include GeneratorSpec::TestCase
6
8
 
7
9
  tests Doorkeeper::ApplicationOwnerGenerator
8
- destination ::File.expand_path('../tmp/dummy', __FILE__)
10
+ destination ::File.expand_path("../tmp/dummy", __FILE__)
9
11
 
10
- describe 'after running the generator' do
12
+ describe "after running the generator" do
11
13
  before :each do
12
14
  prepare_destination
13
15
  end
14
16
 
15
- context 'pre Rails 5.0.0' do
16
- it 'creates a migration with no version specifier' do
17
- stub_const("ActiveRecord::VERSION::MAJOR", 4)
18
- stub_const("ActiveRecord::VERSION::MINOR", 2)
19
-
20
- run_generator
21
-
22
- assert_migration 'db/migrate/add_owner_to_application.rb' do |migration|
23
- assert migration.include?("ActiveRecord::Migration\n")
24
- end
25
- end
26
- end
27
-
28
- context 'post Rails 5.0.0' do
29
- it 'creates a migration with a version specifier' do
30
- stub_const("ActiveRecord::VERSION::MAJOR", 5)
31
- stub_const("ActiveRecord::VERSION::MINOR", 0)
17
+ it "creates a migration with a version specifier" do
18
+ stub_const("ActiveRecord::VERSION::MAJOR", 5)
19
+ stub_const("ActiveRecord::VERSION::MINOR", 0)
32
20
 
33
- run_generator
21
+ run_generator
34
22
 
35
- assert_migration 'db/migrate/add_owner_to_application.rb' do |migration|
36
- assert migration.include?("ActiveRecord::Migration[5.0]\n")
37
- end
23
+ assert_migration "db/migrate/add_owner_to_application.rb" do |migration|
24
+ assert migration.include?("ActiveRecord::Migration[5.0]\n")
38
25
  end
39
26
  end
40
27
  end
@@ -1,44 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
- require 'generators/doorkeeper/confidential_applications_generator'
3
+ require "spec_helper"
4
+ require "generators/doorkeeper/confidential_applications_generator"
5
5
 
6
- describe 'Doorkeeper::ConfidentialApplicationsGenerator' do
6
+ describe "Doorkeeper::ConfidentialApplicationsGenerator" do
7
7
  include GeneratorSpec::TestCase
8
8
 
9
9
  tests Doorkeeper::ConfidentialApplicationsGenerator
10
- destination ::File.expand_path('../tmp/dummy', __FILE__)
10
+ destination ::File.expand_path("../tmp/dummy", __FILE__)
11
11
 
12
- describe 'after running the generator' do
12
+ describe "after running the generator" do
13
13
  before :each do
14
14
  prepare_destination
15
15
  end
16
16
 
17
- context 'pre Rails 5.0.0' do
18
- it 'creates a migration with no version specifier' do
19
- stub_const("ActiveRecord::VERSION::MAJOR", 4)
20
- stub_const("ActiveRecord::VERSION::MINOR", 2)
17
+ it "creates a migration with a version specifier" do
18
+ stub_const("ActiveRecord::VERSION::MAJOR", 5)
19
+ stub_const("ActiveRecord::VERSION::MINOR", 0)
21
20
 
22
- run_generator
21
+ run_generator
23
22
 
24
- assert_migration 'db/migrate/add_confidential_to_applications.rb' do |migration|
25
- assert migration.include?("ActiveRecord::Migration\n")
26
- assert migration.include?(':confidential')
27
- end
28
- end
29
- end
30
-
31
- context 'post Rails 5.0.0' do
32
- it 'creates a migration with a version specifier' do
33
- stub_const("ActiveRecord::VERSION::MAJOR", 5)
34
- stub_const("ActiveRecord::VERSION::MINOR", 0)
35
-
36
- run_generator
37
-
38
- assert_migration 'db/migrate/add_confidential_to_applications.rb' do |migration|
39
- assert migration.include?("ActiveRecord::Migration[5.0]\n")
40
- assert migration.include?(':confidential')
41
- end
23
+ assert_migration "db/migrate/add_confidential_to_applications.rb" do |migration|
24
+ assert migration.include?("ActiveRecord::Migration[5.0]\n")
25
+ assert migration.include?(":confidential")
42
26
  end
43
27
  end
44
28
  end