doorkeeper 4.4.3 → 5.0.3

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 (223) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +16 -0
  4. data/.travis.yml +7 -0
  5. data/Appraisals +2 -2
  6. data/Dangerfile +64 -0
  7. data/Gemfile +1 -1
  8. data/NEWS.md +98 -8
  9. data/README.md +110 -12
  10. data/Rakefile +6 -0
  11. data/UPGRADE.md +2 -0
  12. data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
  13. data/app/controllers/doorkeeper/application_controller.rb +6 -3
  14. data/app/controllers/doorkeeper/application_metal_controller.rb +6 -0
  15. data/app/controllers/doorkeeper/applications_controller.rb +46 -24
  16. data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
  17. data/app/controllers/doorkeeper/authorized_applications_controller.rb +21 -2
  18. data/app/controllers/doorkeeper/token_info_controller.rb +2 -0
  19. data/app/controllers/doorkeeper/tokens_controller.rb +4 -6
  20. data/app/helpers/doorkeeper/dashboard_helper.rb +9 -7
  21. data/app/validators/redirect_uri_validator.rb +5 -2
  22. data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
  23. data/app/views/doorkeeper/applications/_form.html.erb +25 -24
  24. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  25. data/app/views/doorkeeper/applications/index.html.erb +17 -7
  26. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  27. data/app/views/doorkeeper/applications/show.html.erb +6 -6
  28. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  29. data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
  30. data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
  31. data/config/locales/en.yml +10 -1
  32. data/doorkeeper.gemspec +25 -26
  33. data/gemfiles/rails_5_2.gemfile +1 -1
  34. data/gemfiles/rails_master.gemfile +4 -1
  35. data/lib/doorkeeper/config.rb +81 -40
  36. data/lib/doorkeeper/engine.rb +6 -0
  37. data/lib/doorkeeper/errors.rb +17 -3
  38. data/lib/doorkeeper/grape/authorization_decorator.rb +2 -0
  39. data/lib/doorkeeper/grape/helpers.rb +3 -1
  40. data/lib/doorkeeper/helpers/controller.rb +9 -2
  41. data/lib/doorkeeper/models/access_grant_mixin.rb +73 -0
  42. data/lib/doorkeeper/models/access_token_mixin.rb +44 -25
  43. data/lib/doorkeeper/models/application_mixin.rb +2 -0
  44. data/lib/doorkeeper/models/concerns/accessible.rb +2 -0
  45. data/lib/doorkeeper/models/concerns/expirable.rb +2 -0
  46. data/lib/doorkeeper/models/concerns/orderable.rb +2 -0
  47. data/lib/doorkeeper/models/concerns/ownership.rb +2 -0
  48. data/lib/doorkeeper/models/concerns/revocable.rb +2 -0
  49. data/lib/doorkeeper/models/concerns/scopes.rb +3 -1
  50. data/lib/doorkeeper/oauth/authorization/code.rb +33 -8
  51. data/lib/doorkeeper/oauth/authorization/context.rb +17 -0
  52. data/lib/doorkeeper/oauth/authorization/token.rb +38 -14
  53. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +2 -0
  54. data/lib/doorkeeper/oauth/authorization_code_request.rb +29 -2
  55. data/lib/doorkeeper/oauth/base_request.rb +22 -9
  56. data/lib/doorkeeper/oauth/base_response.rb +2 -0
  57. data/lib/doorkeeper/oauth/client/credentials.rb +3 -1
  58. data/lib/doorkeeper/oauth/client.rb +1 -1
  59. data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -1
  60. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +7 -2
  61. data/lib/doorkeeper/oauth/client_credentials/validation.rb +5 -5
  62. data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -3
  63. data/lib/doorkeeper/oauth/code_request.rb +2 -0
  64. data/lib/doorkeeper/oauth/code_response.rb +2 -0
  65. data/lib/doorkeeper/oauth/error.rb +2 -0
  66. data/lib/doorkeeper/oauth/error_response.rb +21 -3
  67. data/lib/doorkeeper/oauth/forbidden_token_response.rb +9 -2
  68. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -8
  69. data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -0
  70. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +5 -2
  71. data/lib/doorkeeper/oauth/invalid_token_response.rb +18 -0
  72. data/lib/doorkeeper/oauth/password_access_token_request.rb +9 -4
  73. data/lib/doorkeeper/oauth/pre_authorization.rb +43 -11
  74. data/lib/doorkeeper/oauth/refresh_token_request.rb +16 -3
  75. data/lib/doorkeeper/oauth/scopes.rb +3 -1
  76. data/lib/doorkeeper/oauth/token.rb +7 -2
  77. data/lib/doorkeeper/oauth/token_introspection.rb +4 -2
  78. data/lib/doorkeeper/oauth/token_request.rb +2 -0
  79. data/lib/doorkeeper/oauth/token_response.rb +6 -2
  80. data/lib/doorkeeper/oauth.rb +13 -0
  81. data/lib/doorkeeper/orm/active_record/application.rb +75 -12
  82. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
  83. data/lib/doorkeeper/orm/active_record.rb +4 -0
  84. data/lib/doorkeeper/rails/helpers.rb +6 -4
  85. data/lib/doorkeeper/rails/routes/mapper.rb +2 -0
  86. data/lib/doorkeeper/rails/routes/mapping.rb +2 -0
  87. data/lib/doorkeeper/rails/routes.rb +23 -8
  88. data/lib/doorkeeper/rake/db.rake +40 -0
  89. data/lib/doorkeeper/rake/setup.rake +6 -0
  90. data/lib/doorkeeper/rake.rb +14 -0
  91. data/lib/doorkeeper/request/authorization_code.rb +1 -1
  92. data/lib/doorkeeper/request/client_credentials.rb +1 -1
  93. data/lib/doorkeeper/request/code.rb +1 -1
  94. data/lib/doorkeeper/request/password.rb +1 -1
  95. data/lib/doorkeeper/request/refresh_token.rb +1 -1
  96. data/lib/doorkeeper/request/strategy.rb +2 -0
  97. data/lib/doorkeeper/request/token.rb +1 -1
  98. data/lib/doorkeeper/request.rb +29 -34
  99. data/lib/doorkeeper/server.rb +2 -0
  100. data/lib/doorkeeper/stale_records_cleaner.rb +20 -0
  101. data/lib/doorkeeper/validations.rb +2 -0
  102. data/lib/doorkeeper/version.rb +6 -24
  103. data/lib/doorkeeper.rb +20 -17
  104. data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
  105. data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
  106. data/lib/generators/doorkeeper/install_generator.rb +17 -9
  107. data/lib/generators/doorkeeper/migration_generator.rb +23 -18
  108. data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
  109. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
  110. data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
  111. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
  112. data/lib/generators/doorkeeper/templates/initializer.rb +96 -13
  113. data/lib/generators/doorkeeper/templates/migration.rb.erb +2 -3
  114. data/lib/generators/doorkeeper/views_generator.rb +3 -1
  115. data/spec/controllers/application_metal_controller_spec.rb +50 -0
  116. data/spec/controllers/applications_controller_spec.rb +123 -14
  117. data/spec/controllers/authorizations_controller_spec.rb +334 -51
  118. data/spec/controllers/protected_resources_controller_spec.rb +60 -18
  119. data/spec/controllers/token_info_controller_spec.rb +4 -12
  120. data/spec/controllers/tokens_controller_spec.rb +17 -20
  121. data/spec/dummy/Rakefile +1 -1
  122. data/spec/dummy/app/assets/config/manifest.js +2 -0
  123. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +1 -1
  124. data/spec/dummy/app/controllers/home_controller.rb +1 -2
  125. data/spec/dummy/config/application.rb +1 -1
  126. data/spec/dummy/config/boot.rb +2 -4
  127. data/spec/dummy/config/environment.rb +1 -1
  128. data/spec/dummy/config/environments/test.rb +5 -6
  129. data/spec/dummy/config/initializers/doorkeeper.rb +12 -6
  130. data/spec/dummy/config/initializers/new_framework_defaults.rb +2 -0
  131. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  132. data/spec/dummy/config/routes.rb +3 -42
  133. data/spec/dummy/config.ru +1 -1
  134. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +4 -4
  135. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +1 -1
  136. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
  137. data/spec/dummy/db/migrate/{20180210183654_add_confidential_to_application.rb → 20180210183654_add_confidential_to_applications.rb} +1 -1
  138. data/spec/dummy/db/schema.rb +36 -36
  139. data/spec/dummy/script/rails +4 -3
  140. data/spec/factories.rb +6 -6
  141. data/spec/generators/application_owner_generator_spec.rb +1 -1
  142. data/spec/generators/confidential_applications_generator_spec.rb +45 -0
  143. data/spec/generators/install_generator_spec.rb +5 -2
  144. data/spec/generators/migration_generator_spec.rb +1 -1
  145. data/spec/generators/pkce_generator_spec.rb +43 -0
  146. data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
  147. data/spec/generators/templates/routes.rb +0 -1
  148. data/spec/generators/views_generator_spec.rb +2 -2
  149. data/spec/grape/grape_integration_spec.rb +2 -2
  150. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  151. data/spec/lib/config_spec.rb +105 -39
  152. data/spec/lib/doorkeeper_spec.rb +6 -131
  153. data/spec/lib/models/expirable_spec.rb +0 -3
  154. data/spec/lib/models/revocable_spec.rb +0 -2
  155. data/spec/lib/models/scopes_spec.rb +0 -4
  156. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
  157. data/spec/lib/oauth/authorization_code_request_spec.rb +17 -7
  158. data/spec/lib/oauth/base_request_spec.rb +49 -11
  159. data/spec/lib/oauth/base_response_spec.rb +1 -1
  160. data/spec/lib/oauth/client/credentials_spec.rb +2 -4
  161. data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
  162. data/spec/lib/oauth/client_credentials/issuer_spec.rb +24 -7
  163. data/spec/lib/oauth/client_credentials/validation_spec.rb +4 -4
  164. data/spec/lib/oauth/client_credentials_integration_spec.rb +2 -2
  165. data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
  166. data/spec/lib/oauth/client_spec.rb +0 -3
  167. data/spec/lib/oauth/code_request_spec.rb +5 -3
  168. data/spec/lib/oauth/code_response_spec.rb +1 -1
  169. data/spec/lib/oauth/error_response_spec.rb +0 -3
  170. data/spec/lib/oauth/error_spec.rb +0 -2
  171. data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
  172. data/spec/lib/oauth/helpers/scope_checker_spec.rb +8 -11
  173. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
  174. data/spec/lib/oauth/helpers/uri_checker_spec.rb +22 -13
  175. data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
  176. data/spec/lib/oauth/password_access_token_request_spec.rb +53 -6
  177. data/spec/lib/oauth/pre_authorization_spec.rb +33 -4
  178. data/spec/lib/oauth/refresh_token_request_spec.rb +22 -14
  179. data/spec/lib/oauth/scopes_spec.rb +0 -3
  180. data/spec/lib/oauth/token_request_spec.rb +8 -9
  181. data/spec/lib/oauth/token_response_spec.rb +0 -1
  182. data/spec/lib/oauth/token_spec.rb +40 -14
  183. data/spec/lib/request/strategy_spec.rb +0 -1
  184. data/spec/lib/server_spec.rb +7 -7
  185. data/spec/lib/stale_records_cleaner_spec.rb +89 -0
  186. data/spec/models/doorkeeper/access_grant_spec.rb +44 -1
  187. data/spec/models/doorkeeper/access_token_spec.rb +80 -32
  188. data/spec/models/doorkeeper/application_spec.rb +293 -221
  189. data/spec/requests/applications/applications_request_spec.rb +134 -1
  190. data/spec/requests/applications/authorized_applications_spec.rb +1 -1
  191. data/spec/requests/endpoints/authorization_spec.rb +3 -3
  192. data/spec/requests/endpoints/token_spec.rb +7 -5
  193. data/spec/requests/flows/authorization_code_errors_spec.rb +2 -2
  194. data/spec/requests/flows/authorization_code_spec.rb +258 -2
  195. data/spec/requests/flows/client_credentials_spec.rb +46 -6
  196. data/spec/requests/flows/implicit_grant_errors_spec.rb +3 -3
  197. data/spec/requests/flows/implicit_grant_spec.rb +38 -11
  198. data/spec/requests/flows/password_spec.rb +61 -3
  199. data/spec/requests/flows/refresh_token_spec.rb +59 -2
  200. data/spec/requests/flows/revoke_token_spec.rb +20 -20
  201. data/spec/requests/flows/skip_authorization_spec.rb +16 -11
  202. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  203. data/spec/requests/protected_resources/private_api_spec.rb +3 -3
  204. data/spec/routing/custom_controller_routes_spec.rb +59 -7
  205. data/spec/routing/default_routes_spec.rb +2 -2
  206. data/spec/routing/scoped_routes_spec.rb +16 -2
  207. data/spec/spec_helper.rb +54 -3
  208. data/spec/spec_helper_integration.rb +2 -74
  209. data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
  210. data/spec/support/doorkeeper_rspec.rb +20 -0
  211. data/spec/support/helpers/authorization_request_helper.rb +4 -4
  212. data/spec/support/helpers/model_helper.rb +8 -4
  213. data/spec/support/helpers/request_spec_helper.rb +10 -2
  214. data/spec/support/helpers/url_helper.rb +18 -14
  215. data/spec/support/http_method_shim.rb +12 -16
  216. data/spec/support/shared/controllers_shared_context.rb +56 -0
  217. data/spec/validators/redirect_uri_validator_spec.rb +9 -3
  218. data/spec/version/version_spec.rb +3 -3
  219. data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
  220. metadata +54 -35
  221. data/lib/generators/doorkeeper/add_client_confidentiality_generator.rb +0 -31
  222. data/lib/generators/doorkeeper/templates/add_confidential_to_application_migration.rb.erb +0 -11
  223. data/spec/controllers/application_metal_controller.rb +0 -10
@@ -1,74 +1,2 @@
1
- if ENV['TRAVIS']
2
- require 'coveralls'
3
-
4
- Coveralls.wear!('rails') do
5
- add_filter('/spec/')
6
- add_filter('/lib/generators/doorkeeper/templates/')
7
- end
8
- else
9
- require 'simplecov'
10
-
11
- SimpleCov.start do
12
- add_filter('/spec/')
13
- add_filter('/lib/generators/doorkeeper/templates/')
14
- end
15
- end
16
-
17
- ENV['RAILS_ENV'] ||= 'test'
18
- TABLE_NAME_PREFIX = ENV['table_name_prefix'] || nil
19
- TABLE_NAME_SUFFIX = ENV['table_name_suffix'] || nil
20
-
21
- orm = (ENV['BUNDLE_GEMFILE'] || '').match(/Gemfile\.(.+)\.rb/)
22
- DOORKEEPER_ORM = (orm && orm[1] || :active_record).to_sym
23
-
24
- $LOAD_PATH.unshift File.dirname(__FILE__)
25
-
26
- require 'capybara/rspec'
27
- require 'dummy/config/environment'
28
- require 'rspec/rails'
29
- require 'generator_spec/test_case'
30
- require 'database_cleaner'
31
-
32
- # Load JRuby SQLite3 if in that platform
33
- begin
34
- require 'jdbc/sqlite3'
35
- Jdbc::SQLite3.load_driver
36
- rescue LoadError
37
- end
38
-
39
- Rails.logger.info "====> Doorkeeper.orm = #{Doorkeeper.configuration.orm}"
40
- if Doorkeeper.configuration.orm == :active_record
41
- Rails.logger.info "======> active_record.table_name_prefix = #{Rails.configuration.active_record.table_name_prefix}"
42
- Rails.logger.info "======> active_record.table_name_suffix = #{Rails.configuration.active_record.table_name_suffix}"
43
- end
44
- Rails.logger.info "====> Rails version: #{Rails.version}"
45
- Rails.logger.info "====> Ruby version: #{RUBY_VERSION}"
46
-
47
- require "support/orm/#{DOORKEEPER_ORM}"
48
-
49
- ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
50
-
51
- Dir["#{File.dirname(__FILE__)}/support/{dependencies,helpers,shared}/*.rb"].each { |f| require f }
52
-
53
- # Remove after dropping support of Rails 4.2
54
- require "#{File.dirname(__FILE__)}/support/http_method_shim.rb"
55
-
56
- RSpec.configure do |config|
57
- config.infer_spec_type_from_file_location!
58
- config.mock_with :rspec
59
-
60
- config.infer_base_class_for_anonymous_controllers = false
61
-
62
- config.include RSpec::Rails::RequestExampleGroup, type: :request
63
-
64
- config.before do
65
- DatabaseCleaner.start
66
- Doorkeeper.configure { orm DOORKEEPER_ORM }
67
- end
68
-
69
- config.after do
70
- DatabaseCleaner.clean
71
- end
72
-
73
- config.order = 'random'
74
- end
1
+ # For compatibility only
2
+ require 'spec_helper'
@@ -0,0 +1,20 @@
1
+ module Doorkeeper
2
+ class RSpec
3
+ # Print's useful information about env: Ruby / Rails versions,
4
+ # Doorkeeper configuration, etc.
5
+ def self.print_configuration_info
6
+ puts <<-INFO.strip_heredoc
7
+ ====> Doorkeeper ORM: '#{Doorkeeper.configuration.orm}'
8
+ ====> Doorkeeper version: #{Doorkeeper.gem_version}
9
+ ====> Rails version: #{::Rails.version}
10
+ ====> Ruby version: #{RUBY_VERSION} on #{RUBY_PLATFORM}
11
+ INFO
12
+ end
13
+
14
+ # Tries to find ORM from the Gemfile used to run test suite
15
+ def self.detect_orm
16
+ orm = (ENV['BUNDLE_GEMFILE'] || '').match(/Gemfile\.(.+)\.rb/)
17
+ (orm && orm[1] || :active_record).to_sym
18
+ end
19
+ end
20
+ end
@@ -28,13 +28,13 @@ module AuthorizationRequestHelper
28
28
  expect(client.redirect_uri).to eq("#{current_uri.scheme}://#{current_uri.host}#{current_uri.path}")
29
29
  end
30
30
 
31
- def allowing_forgery_protection(&block)
32
- _original_value = ActionController::Base.allow_forgery_protection
31
+ def allowing_forgery_protection(&_block)
32
+ original_value = ActionController::Base.allow_forgery_protection
33
33
  ActionController::Base.allow_forgery_protection = true
34
34
 
35
- block.call
35
+ yield
36
36
  ensure
37
- ActionController::Base.allow_forgery_protection = _original_value
37
+ ActionController::Base.allow_forgery_protection = original_value
38
38
  end
39
39
  end
40
40
 
@@ -11,11 +11,15 @@ module ModelHelper
11
11
  @authorization = FactoryBot.create(:access_grant, options)
12
12
  end
13
13
 
14
+ def access_token_exists(options = {})
15
+ @access_token = FactoryBot.create(:access_token, options)
16
+ end
17
+
14
18
  def access_grant_should_exist_for(client, resource_owner)
15
19
  grant = Doorkeeper::AccessGrant.first
16
20
 
17
- expect(grant.application).to have_attributes(id: client.id).
18
- and(be_instance_of(Doorkeeper::Application))
21
+ expect(grant.application).to have_attributes(id: client.id)
22
+ .and(be_instance_of(Doorkeeper::Application))
19
23
 
20
24
  expect(grant.resource_owner_id).to eq(resource_owner.id)
21
25
  end
@@ -23,8 +27,8 @@ module ModelHelper
23
27
  def access_token_should_exist_for(client, resource_owner)
24
28
  token = Doorkeeper::AccessToken.first
25
29
 
26
- expect(token.application).to have_attributes(id: client.id).
27
- and(be_instance_of(Doorkeeper::Application))
30
+ expect(token.application).to have_attributes(id: client.id)
31
+ .and(be_instance_of(Doorkeeper::Application))
28
32
 
29
33
  expect(token.resource_owner_id).to eq(resource_owner.id)
30
34
  end
@@ -1,4 +1,8 @@
1
1
  module RequestSpecHelper
2
+ def i_am_logged_in
3
+ allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(->(*) {})
4
+ end
5
+
2
6
  def i_should_see(content)
3
7
  expect(page).to have_content(content)
4
8
  end
@@ -39,6 +43,10 @@ module RequestSpecHelper
39
43
  expect(headers[header]).to eq(value)
40
44
  end
41
45
 
46
+ def should_have_status(status)
47
+ expect(page.driver.response.status).to eq(status)
48
+ end
49
+
42
50
  def with_access_token_header(token)
43
51
  with_header 'Authorization', "Bearer #{token}"
44
52
  end
@@ -68,8 +76,8 @@ module RequestSpecHelper
68
76
  click_on 'Sign in'
69
77
  end
70
78
 
71
- def create_access_token(authorization_code, client)
72
- page.driver.post token_endpoint_url(code: authorization_code, client: client)
79
+ def create_access_token(authorization_code, client, code_verifier = nil)
80
+ page.driver.post token_endpoint_url(code: authorization_code, client: client, code_verifier: code_verifier)
73
81
  end
74
82
 
75
83
  def i_should_see_translated_error_message(key)
@@ -2,21 +2,23 @@ module UrlHelper
2
2
  def token_endpoint_url(options = {})
3
3
  parameters = {
4
4
  code: options[:code],
5
- client_id: options[:client_id] || (options[:client] ? options[:client].uid : nil),
6
- client_secret: options[:client_secret] || (options[:client] ? options[:client].secret : nil),
7
- redirect_uri: options[:redirect_uri] || (options[:client] ? options[:client].redirect_uri : nil),
8
- grant_type: options[:grant_type] || 'authorization_code'
9
- }
5
+ client_id: options[:client_id] || options[:client].try(:uid),
6
+ client_secret: options[:client_secret] || options[:client].try(:secret),
7
+ redirect_uri: options[:redirect_uri] || options[:client].try(:redirect_uri),
8
+ grant_type: options[:grant_type] || 'authorization_code',
9
+ code_verifier: options[:code_verifier],
10
+ code_challenge_method: options[:code_challenge_method]
11
+ }.reject { |_, v| v.blank? }
10
12
  "/oauth/token?#{build_query(parameters)}"
11
13
  end
12
14
 
13
15
  def password_token_endpoint_url(options = {})
14
16
  parameters = {
15
17
  code: options[:code],
16
- client_id: options[:client_id] || (options[:client] ? options[:client].uid : nil),
17
- client_secret: options[:client_secret] || (options[:client] ? options[:client].secret : nil),
18
- username: options[:resource_owner_username] || (options[:resource_owner] ? options[:resource_owner].name : nil),
19
- password: options[:resource_owner_password] || (options[:resource_owner] ? options[:resource_owner].password : nil),
18
+ client_id: options[:client_id] || options[:client].try(:uid),
19
+ client_secret: options[:client_secret] || options[:client].try(:secret),
20
+ username: options[:resource_owner_username] || options[:resource_owner].try(:name),
21
+ password: options[:resource_owner_password] || options[:resource_owner].try(:password),
20
22
  scope: options[:scope],
21
23
  grant_type: 'password'
22
24
  }
@@ -25,11 +27,13 @@ module UrlHelper
25
27
 
26
28
  def authorization_endpoint_url(options = {})
27
29
  parameters = {
28
- client_id: options[:client_id] || options[:client].uid,
29
- redirect_uri: options[:redirect_uri] || options[:client].redirect_uri,
30
+ client_id: options[:client_id] || options[:client].try(:uid),
31
+ redirect_uri: options[:redirect_uri] || options[:client].try(:redirect_uri),
30
32
  response_type: options[:response_type] || 'code',
31
33
  scope: options[:scope],
32
- state: options[:state]
34
+ state: options[:state],
35
+ code_challenge: options[:code_challenge],
36
+ code_challenge_method: options[:code_challenge_method]
33
37
  }.reject { |_, v| v.blank? }
34
38
  "/oauth/authorize?#{build_query(parameters)}"
35
39
  end
@@ -37,8 +41,8 @@ module UrlHelper
37
41
  def refresh_token_endpoint_url(options = {})
38
42
  parameters = {
39
43
  refresh_token: options[:refresh_token],
40
- client_id: options[:client_id] || options[:client].uid,
41
- client_secret: options[:client_secret] || options[:client].secret,
44
+ client_id: options[:client_id] || options[:client].try(:uid),
45
+ client_secret: options[:client_secret] || options[:client].try(:secret),
42
46
  grant_type: options[:grant_type] || 'refresh_token'
43
47
  }
44
48
  "/oauth/token?#{build_query(parameters)}"
@@ -3,34 +3,30 @@
3
3
  # supported in Rails 5+. Since we support back to 4, we need some sort of shim
4
4
  # to avoid super noisy deprecations when running tests.
5
5
  module RoutingHTTPMethodShim
6
- def get(path, params = {}, headers = nil)
7
- super(path, params: params, headers: headers)
6
+ def get(path, **args)
7
+ super(path, args[:params], args[:headers])
8
8
  end
9
9
 
10
- def post(path, params = {}, headers = nil)
11
- super(path, params: params, headers: headers)
10
+ def post(path, **args)
11
+ super(path, args[:params], args[:headers])
12
12
  end
13
13
 
14
- def put(path, params = {}, headers = nil)
15
- super(path, params: params, headers: headers)
14
+ def put(path, **args)
15
+ super(path, args[:params], args[:headers])
16
16
  end
17
17
  end
18
18
 
19
19
  module ControllerHTTPMethodShim
20
- def get(path, params = {})
21
- super(path, params: params)
22
- end
23
-
24
- def post(path, params = {})
25
- super(path, params: params)
26
- end
20
+ def process(action, http_method = 'GET', **args)
21
+ if (as = args.delete(:as))
22
+ @request.headers['Content-Type'] = Mime[as].to_s
23
+ end
27
24
 
28
- def put(path, params = {})
29
- super(path, params: params)
25
+ super(action, http_method, args[:params], args[:session], args[:flash])
30
26
  end
31
27
  end
32
28
 
33
- if ::Rails::VERSION::MAJOR >= 5
29
+ if ::Rails::VERSION::MAJOR < 5
34
30
  RSpec.configure do |config|
35
31
  config.include ControllerHTTPMethodShim, type: :controller
36
32
  config.include RoutingHTTPMethodShim, type: :request
@@ -63,3 +63,59 @@ shared_context 'invalid authorization request' do
63
63
  allow(controller).to receive(:authorization) { authorization }
64
64
  end
65
65
  end
66
+
67
+ shared_context 'expired token', token: :expired do
68
+ let :token_string do
69
+ '1A2B3C4DEXP'
70
+ end
71
+
72
+ let :token do
73
+ double(Doorkeeper::AccessToken,
74
+ accessible?: false, revoked?: false, expired?: true,
75
+ includes_scope?: false, acceptable?: false,
76
+ previous_refresh_token: "", revoke_previous_refresh_token!: true)
77
+ end
78
+
79
+ before :each do
80
+ allow(
81
+ Doorkeeper::AccessToken
82
+ ).to receive(:by_token).with(token_string).and_return(token)
83
+ end
84
+ end
85
+
86
+ shared_context 'revoked token', token: :revoked do
87
+ let :token_string do
88
+ '1A2B3C4DREV'
89
+ end
90
+
91
+ let :token do
92
+ double(Doorkeeper::AccessToken,
93
+ accessible?: false, revoked?: true, expired?: false,
94
+ includes_scope?: false, acceptable?: false,
95
+ previous_refresh_token: "", revoke_previous_refresh_token!: true)
96
+ end
97
+
98
+ before :each do
99
+ allow(
100
+ Doorkeeper::AccessToken
101
+ ).to receive(:by_token).with(token_string).and_return(token)
102
+ end
103
+ end
104
+
105
+ shared_context 'forbidden token', token: :forbidden do
106
+ let :token_string do
107
+ '1A2B3C4DFORB'
108
+ end
109
+
110
+ let :token do
111
+ double(Doorkeeper::AccessToken,
112
+ accessible?: true, includes_scope?: true, acceptable?: false,
113
+ previous_refresh_token: "", revoke_previous_refresh_token!: true)
114
+ end
115
+
116
+ before :each do
117
+ allow(
118
+ Doorkeeper::AccessToken
119
+ ).to receive(:by_token).with(token_string).and_return(token)
120
+ end
121
+ end
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  describe RedirectUriValidator do
4
4
  subject do
@@ -73,8 +73,8 @@ describe RedirectUriValidator do
73
73
  it 'accepts a non secured protocol when disabled' do
74
74
  subject.redirect_uri = 'http://example.com/callback'
75
75
  allow(Doorkeeper.configuration).to receive(
76
- :force_ssl_in_redirect_uri
77
- ).and_return(false)
76
+ :force_ssl_in_redirect_uri
77
+ ).and_return(false)
78
78
  expect(subject).to be_valid
79
79
  end
80
80
 
@@ -87,8 +87,14 @@ describe RedirectUriValidator do
87
87
  application = FactoryBot.build(:application, redirect_uri: 'http://localhost/callback')
88
88
  expect(application).to be_valid
89
89
 
90
+ application = FactoryBot.build(:application, redirect_uri: 'https://test.com/callback')
91
+ expect(application).to be_valid
92
+
90
93
  application = FactoryBot.build(:application, redirect_uri: 'http://localhost2/callback')
91
94
  expect(application).not_to be_valid
95
+
96
+ application = FactoryBot.build(:application, redirect_uri: 'https://test.com/callback')
97
+ expect(application).to be_valid
92
98
  end
93
99
 
94
100
  it 'forbids redirect uri if required' do
@@ -1,6 +1,6 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
- describe 'Doorkeeper version' do
3
+ describe Doorkeeper::VERSION do
4
4
  context '#gem_version' do
5
5
  it 'returns Gem::Version instance' do
6
6
  expect(Doorkeeper.gem_version).to be_an_instance_of(Gem::Version)
@@ -9,7 +9,7 @@ describe 'Doorkeeper version' do
9
9
 
10
10
  context 'VERSION' do
11
11
  it 'returns gem version string' do
12
- expect(Doorkeeper::VERSION::STRING).to match(/^\d+\.\d+\.\d+[.\w]?$/)
12
+ expect(Doorkeeper::VERSION::STRING).to match(/^\d+\.\d+\.\d+(\.\w+)?$/)
13
13
  end
14
14
  end
15
15
  end