doorkeeper 5.0.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -0
  3. data/Dangerfile +64 -0
  4. data/NEWS.md +37 -1
  5. data/README.md +18 -3
  6. data/app/controllers/doorkeeper/application_controller.rb +2 -0
  7. data/app/controllers/doorkeeper/application_metal_controller.rb +2 -0
  8. data/app/controllers/doorkeeper/applications_controller.rb +4 -2
  9. data/app/controllers/doorkeeper/authorizations_controller.rb +3 -3
  10. data/app/controllers/doorkeeper/authorized_applications_controller.rb +2 -0
  11. data/app/controllers/doorkeeper/token_info_controller.rb +2 -0
  12. data/app/controllers/doorkeeper/tokens_controller.rb +2 -0
  13. data/app/helpers/doorkeeper/dashboard_helper.rb +2 -0
  14. data/app/validators/redirect_uri_validator.rb +2 -0
  15. data/doorkeeper.gemspec +23 -22
  16. data/lib/doorkeeper/config.rb +7 -2
  17. data/lib/doorkeeper/engine.rb +2 -0
  18. data/lib/doorkeeper/errors.rb +17 -0
  19. data/lib/doorkeeper/grape/authorization_decorator.rb +2 -0
  20. data/lib/doorkeeper/grape/helpers.rb +2 -0
  21. data/lib/doorkeeper/helpers/controller.rb +2 -0
  22. data/lib/doorkeeper/models/access_grant_mixin.rb +5 -3
  23. data/lib/doorkeeper/models/access_token_mixin.rb +5 -3
  24. data/lib/doorkeeper/models/application_mixin.rb +2 -0
  25. data/lib/doorkeeper/models/concerns/accessible.rb +2 -0
  26. data/lib/doorkeeper/models/concerns/expirable.rb +2 -0
  27. data/lib/doorkeeper/models/concerns/orderable.rb +2 -0
  28. data/lib/doorkeeper/models/concerns/ownership.rb +2 -0
  29. data/lib/doorkeeper/models/concerns/revocable.rb +2 -0
  30. data/lib/doorkeeper/models/concerns/scopes.rb +2 -0
  31. data/lib/doorkeeper/oauth/authorization/code.rb +2 -0
  32. data/lib/doorkeeper/oauth/authorization/context.rb +2 -0
  33. data/lib/doorkeeper/oauth/authorization/token.rb +2 -0
  34. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +2 -0
  35. data/lib/doorkeeper/oauth/authorization_code_request.rb +2 -0
  36. data/lib/doorkeeper/oauth/base_request.rb +2 -0
  37. data/lib/doorkeeper/oauth/base_response.rb +2 -0
  38. data/lib/doorkeeper/oauth/client/credentials.rb +2 -0
  39. data/lib/doorkeeper/oauth/client.rb +2 -0
  40. data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -0
  41. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +2 -0
  42. data/lib/doorkeeper/oauth/client_credentials/validation.rb +2 -0
  43. data/lib/doorkeeper/oauth/client_credentials_request.rb +2 -0
  44. data/lib/doorkeeper/oauth/code_request.rb +2 -0
  45. data/lib/doorkeeper/oauth/code_response.rb +2 -0
  46. data/lib/doorkeeper/oauth/error.rb +2 -0
  47. data/lib/doorkeeper/oauth/error_response.rb +10 -0
  48. data/lib/doorkeeper/oauth/forbidden_token_response.rb +9 -2
  49. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -0
  50. data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -0
  51. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +5 -2
  52. data/lib/doorkeeper/oauth/invalid_token_response.rb +18 -0
  53. data/lib/doorkeeper/oauth/password_access_token_request.rb +2 -0
  54. data/lib/doorkeeper/oauth/pre_authorization.rb +2 -0
  55. data/lib/doorkeeper/oauth/refresh_token_request.rb +10 -2
  56. data/lib/doorkeeper/oauth/scopes.rb +2 -0
  57. data/lib/doorkeeper/oauth/token.rb +2 -0
  58. data/lib/doorkeeper/oauth/token_introspection.rb +2 -0
  59. data/lib/doorkeeper/oauth/token_request.rb +2 -0
  60. data/lib/doorkeeper/oauth/token_response.rb +2 -0
  61. data/lib/doorkeeper/orm/active_record.rb +2 -0
  62. data/lib/doorkeeper/rails/helpers.rb +4 -0
  63. data/lib/doorkeeper/rails/routes/mapper.rb +2 -0
  64. data/lib/doorkeeper/rails/routes/mapping.rb +2 -0
  65. data/lib/doorkeeper/rails/routes.rb +9 -2
  66. data/lib/doorkeeper/rake/db.rake +4 -4
  67. data/lib/doorkeeper/request/authorization_code.rb +2 -0
  68. data/lib/doorkeeper/request/client_credentials.rb +2 -0
  69. data/lib/doorkeeper/request/code.rb +2 -0
  70. data/lib/doorkeeper/request/password.rb +2 -0
  71. data/lib/doorkeeper/request/refresh_token.rb +2 -0
  72. data/lib/doorkeeper/request/strategy.rb +2 -0
  73. data/lib/doorkeeper/request/token.rb +2 -0
  74. data/lib/doorkeeper/request.rb +2 -0
  75. data/lib/doorkeeper/server.rb +2 -0
  76. data/lib/doorkeeper/stale_records_cleaner.rb +20 -0
  77. data/lib/doorkeeper/validations.rb +2 -0
  78. data/lib/doorkeeper/version.rb +3 -1
  79. data/lib/doorkeeper.rb +1 -0
  80. data/lib/generators/doorkeeper/templates/initializer.rb +20 -2
  81. data/lib/generators/doorkeeper/templates/migration.rb.erb +2 -3
  82. data/spec/controllers/applications_controller_spec.rb +37 -41
  83. data/spec/controllers/authorizations_controller_spec.rb +71 -18
  84. data/spec/controllers/protected_resources_controller_spec.rb +44 -2
  85. data/spec/controllers/tokens_controller_spec.rb +4 -5
  86. data/spec/dummy/Rakefile +1 -1
  87. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +1 -1
  88. data/spec/dummy/app/controllers/home_controller.rb +1 -2
  89. data/spec/dummy/config/application.rb +1 -1
  90. data/spec/dummy/config/boot.rb +2 -4
  91. data/spec/dummy/config/environment.rb +1 -1
  92. data/spec/dummy/config/environments/test.rb +1 -1
  93. data/spec/dummy/config/initializers/doorkeeper.rb +2 -1
  94. data/spec/dummy/config/initializers/new_framework_defaults.rb +1 -3
  95. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  96. data/spec/dummy/config.ru +1 -1
  97. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +4 -4
  98. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +1 -1
  99. data/spec/dummy/script/rails +4 -3
  100. data/spec/factories.rb +6 -6
  101. data/spec/generators/install_generator_spec.rb +4 -1
  102. data/spec/generators/templates/routes.rb +0 -1
  103. data/spec/generators/views_generator_spec.rb +1 -1
  104. data/spec/grape/grape_integration_spec.rb +1 -1
  105. data/spec/lib/config_spec.rb +25 -8
  106. data/spec/lib/doorkeeper_spec.rb +5 -5
  107. data/spec/lib/oauth/authorization_code_request_spec.rb +9 -6
  108. data/spec/lib/oauth/base_request_spec.rb +10 -10
  109. data/spec/lib/oauth/client/credentials_spec.rb +2 -2
  110. data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -2
  111. data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -1
  112. data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
  113. data/spec/lib/oauth/code_request_spec.rb +2 -2
  114. data/spec/lib/oauth/code_response_spec.rb +1 -1
  115. data/spec/lib/oauth/helpers/scope_checker_spec.rb +8 -8
  116. data/spec/lib/oauth/helpers/uri_checker_spec.rb +17 -6
  117. data/spec/lib/oauth/password_access_token_request_spec.rb +17 -5
  118. data/spec/lib/oauth/refresh_token_request_spec.rb +11 -7
  119. data/spec/lib/oauth/token_request_spec.rb +5 -5
  120. data/spec/lib/oauth/token_spec.rb +4 -1
  121. data/spec/lib/server_spec.rb +6 -6
  122. data/spec/lib/{orm/active_record/stale_records_cleaner_spec.rb → stale_records_cleaner_spec.rb} +14 -4
  123. data/spec/models/doorkeeper/access_token_spec.rb +14 -10
  124. data/spec/models/doorkeeper/application_spec.rb +4 -4
  125. data/spec/requests/applications/applications_request_spec.rb +2 -2
  126. data/spec/requests/endpoints/authorization_spec.rb +2 -2
  127. data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
  128. data/spec/requests/flows/authorization_code_spec.rb +75 -15
  129. data/spec/requests/flows/implicit_grant_errors_spec.rb +2 -2
  130. data/spec/requests/flows/password_spec.rb +6 -2
  131. data/spec/requests/flows/refresh_token_spec.rb +57 -0
  132. data/spec/requests/flows/revoke_token_spec.rb +9 -9
  133. data/spec/requests/protected_resources/private_api_spec.rb +2 -2
  134. data/spec/support/doorkeeper_rspec.rb +2 -1
  135. data/spec/support/helpers/model_helper.rb +8 -4
  136. data/spec/support/helpers/url_helper.rb +11 -11
  137. data/spec/support/shared/controllers_shared_context.rb +56 -0
  138. data/spec/validators/redirect_uri_validator_spec.rb +2 -2
  139. metadata +20 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db3333346ca1b82cd7aa332bb1e43f8d979534c0
4
- data.tar.gz: 12511ea5d14b0bba28fef47893cc925c9e45ebcd
3
+ metadata.gz: 3a0fa2d314b8aa479233379028c00d8107830f46
4
+ data.tar.gz: c0bb3f5658cbbc4f7b640e08ae418afab36d7225
5
5
  SHA512:
6
- metadata.gz: a5265ed62b206c4f9f117c3cbc8e6d905840636297a342ea952e5dfced01f7ce4bd6b59fc7efd6a4f0e6558475c566bf59ba4a793ef3f87942cf8935dde061ba
7
- data.tar.gz: 18d2b90ae8e5f2e6e80f518fe0a251c49ba3187fda34c9213f14c0152f301dfd149d11db14dcd94a69bb8048352f8a945107c572cfb3fa03aeabc6d6383b706c
6
+ metadata.gz: 45411b41e6ca7e5b3016b6831efa7cb6df93dcca172ac1902a8561ca004f6701ebaf4364d5e12d439bd0867533aa4b98133224482cd91ce015b835b26753dc64
7
+ data.tar.gz: 89aaf99254db0422ce86ed21f6e604ce8ecac6eb6c58070170b88be0fa02c338b71e7683d95f557319d75936e53f464e47118fbc85c35ac8a97cfd1588202622
data/.travis.yml CHANGED
@@ -23,6 +23,11 @@ gemfile:
23
23
 
24
24
  matrix:
25
25
  fast_finish: true
26
+ # Run Danger only once
27
+ include:
28
+ - rvm: 2.5
29
+ gemfile: gemfiles/rails_5_2.gemfile
30
+ script: bundle exec danger
26
31
  exclude:
27
32
  - gemfile: gemfiles/rails_5_0.gemfile
28
33
  rvm: 2.1
data/Dangerfile ADDED
@@ -0,0 +1,64 @@
1
+ CHANGELOG_FILE = 'NEWS.md'
2
+ GITHUB_REPO = 'https://github.com/doorkeeper-gem/doorkeeper'
3
+
4
+ def changelog_changed?
5
+ git.modified_files.include?(CHANGELOG_FILE) || git.added_files.include?(CHANGELOG_FILE)
6
+ end
7
+
8
+ def changelog_entry_example
9
+ pr_number = github.pr_json['number']
10
+ pr_title = github.pr_title
11
+ .sub(/[?.!,;]?$/, '')
12
+ .capitalize
13
+
14
+ "- [##{pr_number}]: #{pr_title}."
15
+ end
16
+
17
+ # --------------------------------------------------------------------------------------------------------------------
18
+ # Has any changes happened inside the actual library code?
19
+ # --------------------------------------------------------------------------------------------------------------------
20
+ has_app_changes = !git.modified_files.grep(/lib/).empty?
21
+ has_spec_changes = !git.modified_files.grep(/spec/).empty?
22
+
23
+ # --------------------------------------------------------------------------------------------------------------------
24
+ # You've made changes to lib, but didn't write any tests?
25
+ # --------------------------------------------------------------------------------------------------------------------
26
+ if has_app_changes && !has_spec_changes
27
+ warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false)
28
+ end
29
+
30
+ # --------------------------------------------------------------------------------------------------------------------
31
+ # You've made changes to specs, but no library code has changed?
32
+ # --------------------------------------------------------------------------------------------------------------------
33
+ if !has_app_changes && has_spec_changes
34
+ message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false)
35
+ end
36
+
37
+ # Mainly to encourage writing up some reasoning about the PR, rather than
38
+ # just leaving a title
39
+ if github.pr_body.length < 10
40
+ fail "Please provide a summary in the Pull Request description"
41
+ end
42
+
43
+ # --------------------------------------------------------------------------------------------------------------------
44
+ # Have you updated CHANGELOG.md?
45
+ # --------------------------------------------------------------------------------------------------------------------
46
+ # Add a CHANGELOG entry for app changes
47
+ if has_app_changes && !changelog_changed?
48
+ markdown <<-MARKDOWN
49
+ Here's an example of a #{CHANGELOG_FILE} entry:
50
+ ```markdown
51
+ #{changelog_entry_example}
52
+ ```
53
+ MARKDOWN
54
+
55
+ fail("Please include a changelog entry. \nYou can find it at [#{CHANGELOG_FILE}](#{GITHUB_REPO}/blob/master/#{CHANGELOG_FILE}).")
56
+ end
57
+
58
+ if git.commits.any? { |commit| commit.message =~ /^Merge branch '#{github.branch_for_base}'/ }
59
+ warn('Please rebase to get rid of the merge commits in this PR')
60
+ end
61
+
62
+ if git.commits.length > 1
63
+ warn('Please squash all your commits to a single one')
64
+ end
data/NEWS.md CHANGED
@@ -7,7 +7,22 @@ User-visible changes worth mentioning.
7
7
 
8
8
  ## master
9
9
 
10
- - [#PR ID] Add PR description.
10
+ - [#] Add your description here.
11
+
12
+ ## 5.0.2
13
+
14
+ - [#1158] Fix initializer template: change `handle_auth_errors` option
15
+ - [#1157] Remove redundant index from migration template.
16
+
17
+ ## 5.0.1
18
+
19
+ - [#1140] Allow rendering custom errors from exceptions (issue #844). Originally opened as [#944].
20
+ - [#1138] Revert regression bug (check for token expiration in Authorizations controller so authorization
21
+ triggers every time)
22
+ - [#1149] Fix for `URIChecker#valid_for_authorization?` false negative when query is blank, but `?` present.
23
+ - [#1151] Fix Refresh Token strategy: add proper validation of client credentials both for Public & Private clients.
24
+ - [#1152] Fix migration template: change resource owner data type from integer to Rails generic `references`
25
+ - [#1154] Refactor `StaleRecordsCleaner` to be ORM agnostic.
11
26
 
12
27
  ## 5.0.0
13
28
 
@@ -43,6 +58,12 @@ User-visible changes worth mentioning.
43
58
  `Doorkeeper#installed?` method
44
59
  - [#1031] Allow public clients to authenticate without `client_secret`. Define an app as
45
60
  either public or private/confidential
61
+
62
+ **[IMPORTANT]**: all the applications (clients) now are considered as private by default.
63
+ You need to manually change `confidential` column to `false` if you are using public clients,
64
+ in other case your mobile (or other) applications will not be able to authorize.
65
+ See [#1142](https://github.com/doorkeeper-gem/doorkeeper/issues/1142) for more details.
66
+
46
67
  - [#1010] Add configuration to enforce configured scopes (`default_scopes` and
47
68
  `optional_scopes`) for applications
48
69
  - [#1060] Ensure that the native redirect_uri parameter matches with redirect_uri of the client
@@ -61,6 +82,12 @@ User-visible changes worth mentioning.
61
82
  - Fix bug with `force_ssl_in_redirect_uri` when it breaks existing applications with an
62
83
  SSL redirect_uri.
63
84
 
85
+ ## 4.4.3
86
+
87
+ - [#1143] Adds a config option `opt_out_native_route_change` to opt out of the breaking api
88
+ changed introduced in https://github.com/doorkeeper-gem/doorkeeper/pull/1003
89
+
90
+
64
91
  ## 4.4.2
65
92
 
66
93
  - [#1130] Backport fix for native redirect_uri from 5.x.
@@ -73,6 +100,11 @@ User-visible changes worth mentioning.
73
100
  ## 4.4.0
74
101
 
75
102
  - [#1120] Backport security fix from 5.x for token revocation when using public clients
103
+
104
+ **[IMPORTANT]**: all the applications (clients) now are considered as private by default.
105
+ You need to manually change `confidential` column to `false` if you are using public clients,
106
+ in other case your mobile (or other) applications will not be able to authorize.
107
+ See [#1142](https://github.com/doorkeeper-gem/doorkeeper/issues/1142) for more details.
76
108
 
77
109
  ## 4.3.2
78
110
 
@@ -101,6 +133,10 @@ User-visible changes worth mentioning.
101
133
  - [#985] Generate valid migration files for Rails >= 5
102
134
  - [#972] Replace Struct subclassing with block-form initialization
103
135
  - [#1003] Use URL query param to pass through native redirect auth code so automated apps can find it.
136
+
137
+ **[IMPORTANT]**: Previously authorization code response route was `/oauth/authorize/<code>`,
138
+ now it is `oauth/authorize/native?code=<code>` (in order to help applications to automatically find the code value).
139
+
104
140
  - [#868] `Scopes#&` and `Scopes#+` now take an array or any other enumerable
105
141
  object.
106
142
  - [#1019] Remove translation not in use: `invalid_resource_owner`.
data/README.md CHANGED
@@ -23,6 +23,9 @@ Supported features:
23
23
  - [OAuth 2.0 Token Revocation](http://tools.ietf.org/html/rfc7009)
24
24
  - [OAuth 2.0 Token Introspection](https://tools.ietf.org/html/rfc7662)
25
25
 
26
+ See [list of tutorials](https://github.com/doorkeeper-gem/doorkeeper/wiki#how-tos--tutorials) in order to
27
+ learn how to use the gem or integrate it with other solutions / gems.
28
+
26
29
  ## Documentation valid for `master` branch
27
30
 
28
31
  Please check the documentation for the version of doorkeeper you are using in:
@@ -50,6 +53,7 @@ https://github.com/doorkeeper-gem/doorkeeper/releases
50
53
  - [Routes](#routes)
51
54
  - [Authenticating](#authenticating)
52
55
  - [Internationalization (I18n)](#internationalization-i18n)
56
+ - [Customizing errors](#customizing-errors)
53
57
  - [Rake Tasks](#rake-tasks)
54
58
  - [Protecting resources with OAuth (a.k.a your API endpoint)](#protecting-resources-with-oauth-aka-your-api-endpoint)
55
59
  - [Ruby on Rails controllers](#ruby-on-rails-controllers)
@@ -237,6 +241,14 @@ You may want to check other ways of authentication
237
241
  Doorkeeper support multiple languages. See language files in
238
242
  [the I18n repository](https://github.com/doorkeeper-gem/doorkeeper-i18n).
239
243
 
244
+ ### Customizing errors
245
+
246
+ If you don't want to use default Doorkeeper error responses you can raise and rescue it's
247
+ exceptions. All you need is to set configuration option `handle_auth_errors` to `:raise`.
248
+ In this case Doorkeeper will raise `Doorkeeper::Errors::TokenForbidden`,
249
+ `Doorkeeper::Errors::TokenExpired`, `Doorkeeper::Errors::TokenRevoked` or other exceptions
250
+ that you need to care about.
251
+
240
252
  ### Rake Tasks
241
253
 
242
254
  If you are using `rake`, you can load rake tasks provided by this gem, by adding
@@ -372,7 +384,7 @@ end
372
384
  Please note that there is a logical OR between multiple required scopes. In the
373
385
  above example, `doorkeeper_authorize! :admin, :write` means that the access
374
386
  token is required to have either `:admin` scope or `:write` scope, but does not
375
- need have both of them.
387
+ need to have both of them.
376
388
 
377
389
  If you want to require the access token to have multiple scopes at the same
378
390
  time, use multiple `doorkeeper_authorize!`, for example:
@@ -448,8 +460,11 @@ token owner.
448
460
 
449
461
  ### Applications list
450
462
 
451
- By default, the applications list (`/oauth/applications`) is publicly available.
452
- To protect the endpoint you should uncomment these lines:
463
+ By default, the applications list (`/oauth/applications`) is publicly available (before 5.0 release).
464
+ Starting from Doorkeeper 5.0 it returns 403 Forbidden if `admin_authenticator` option is not configured
465
+ by developers.
466
+
467
+ To change the protection rules of this endpoint you should uncomment these lines:
453
468
 
454
469
  ```ruby
455
470
  # config/initializers/doorkeeper.rb
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class ApplicationController <
3
5
  Doorkeeper.configuration.base_controller.constantize
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class ApplicationMetalController < ActionController::Metal
3
5
  MODULES = [
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class ApplicationsController < Doorkeeper::ApplicationController
3
5
  layout 'doorkeeper/admin' unless Doorkeeper.configuration.api_only
@@ -77,8 +79,8 @@ module Doorkeeper
77
79
  end
78
80
 
79
81
  def application_params
80
- params.require(:doorkeeper_application).
81
- permit(:name, :redirect_uri, :scopes, :confidential)
82
+ params.require(:doorkeeper_application)
83
+ .permit(:name, :redirect_uri, :scopes, :confidential)
82
84
  end
83
85
  end
84
86
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class AuthorizationsController < Doorkeeper::ApplicationController
3
5
  before_action :authenticate_resource_owner!
@@ -41,13 +43,11 @@ module Doorkeeper
41
43
  end
42
44
 
43
45
  def matching_token?
44
- token = AccessToken.matching_token_for(
46
+ AccessToken.matching_token_for(
45
47
  pre_auth.client,
46
48
  current_resource_owner.id,
47
49
  pre_auth.scopes
48
50
  )
49
-
50
- token && token.accessible?
51
51
  end
52
52
 
53
53
  def redirect_or_render(auth)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class AuthorizedApplicationsController < Doorkeeper::ApplicationController
3
5
  before_action :authenticate_resource_owner!
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class TokenInfoController < Doorkeeper::ApplicationMetalController
3
5
  def show
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class TokensController < Doorkeeper::ApplicationMetalController
3
5
  def create
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module DashboardHelper
3
5
  def doorkeeper_errors_for(object, method)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  class RedirectUriValidator < ActiveModel::EachValidator
data/doorkeeper.gemspec CHANGED
@@ -2,29 +2,30 @@ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  require 'doorkeeper/version'
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = 'doorkeeper'
7
- s.version = Doorkeeper.gem_version
8
- s.authors = ['Felipe Elias Philipp', 'Tute Costa', 'Jon Moss', 'Nikita Bulai']
9
- s.email = %w(bulaj.nikita@gmail.com)
10
- s.homepage = 'https://github.com/doorkeeper-gem/doorkeeper'
11
- s.summary = 'OAuth 2 provider for Rails and Grape'
12
- s.description = 'Doorkeeper is an OAuth 2 provider for Rails and Grape.'
13
- s.license = 'MIT'
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'doorkeeper'
7
+ gem.version = Doorkeeper.gem_version
8
+ gem.authors = ['Felipe Elias Philipp', 'Tute Costa', 'Jon Moss', 'Nikita Bulai']
9
+ gem.email = %w(bulaj.nikita@gmail.com)
10
+ gem.homepage = 'https://github.com/doorkeeper-gem/doorkeeper'
11
+ gem.summary = 'OAuth 2 provider for Rails and Grape'
12
+ gem.description = 'Doorkeeper is an OAuth 2 provider for Rails and Grape.'
13
+ gem.license = 'MIT'
14
14
 
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- spec/*`.split("\n")
17
- s.require_paths = ['lib']
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- spec/*`.split("\n")
17
+ gem.require_paths = ['lib']
18
18
 
19
- s.add_dependency 'railties', '>= 4.2'
20
- s.required_ruby_version = '>= 2.1'
19
+ gem.add_dependency 'railties', '>= 4.2'
20
+ gem.required_ruby_version = '>= 2.1'
21
21
 
22
- s.add_development_dependency 'capybara', '~> 2.18'
23
- s.add_development_dependency 'coveralls'
24
- s.add_development_dependency 'grape'
25
- s.add_development_dependency 'database_cleaner', '~> 1.6'
26
- s.add_development_dependency 'factory_bot', '~> 4.8'
27
- s.add_development_dependency 'generator_spec', '~> 0.9.3'
28
- s.add_development_dependency 'rake', '>= 11.3.0'
29
- s.add_development_dependency 'rspec-rails'
22
+ gem.add_development_dependency 'capybara', '~> 2.18'
23
+ gem.add_development_dependency 'coveralls'
24
+ gem.add_development_dependency 'danger', '~> 5.0'
25
+ gem.add_development_dependency 'grape'
26
+ gem.add_development_dependency 'database_cleaner', '~> 1.6'
27
+ gem.add_development_dependency 'factory_bot', '~> 4.8'
28
+ gem.add_development_dependency 'generator_spec', '~> 0.9.3'
29
+ gem.add_development_dependency 'rake', '>= 11.3.0'
30
+ gem.add_development_dependency 'rspec-rails'
30
31
  end
@@ -107,7 +107,7 @@ module Doorkeeper
107
107
  def use_refresh_token(enabled = true, &block)
108
108
  @config.instance_variable_set(
109
109
  :@refresh_token_enabled,
110
- block ? block : enabled
110
+ block || enabled
111
111
  )
112
112
  end
113
113
 
@@ -177,7 +177,7 @@ module Doorkeeper
177
177
  value = if attribute_builder
178
178
  attribute_builder.new(&block).build
179
179
  else
180
- block ? block : args.first
180
+ block || args.first
181
181
  end
182
182
 
183
183
  @config.instance_variable_set(:"@#{attribute}", value)
@@ -239,6 +239,7 @@ module Doorkeeper
239
239
  option :native_redirect_uri, default: 'urn:ietf:wg:oauth:2.0:oob'
240
240
  option :active_record_options, default: {}
241
241
  option :grant_flows, default: %w[authorization_code client_credentials]
242
+ option :handle_auth_errors, default: :render
242
243
 
243
244
  # Allows to forbid specific Application redirect URI's by custom rules.
244
245
  # Doesn't forbid any URI by default.
@@ -317,6 +318,10 @@ module Doorkeeper
317
318
  !!(defined?(@confirm_application_owner) && @confirm_application_owner)
318
319
  end
319
320
 
321
+ def raise_on_errors?
322
+ handle_auth_errors == :raise
323
+ end
324
+
320
325
  def default_scopes
321
326
  @default_scopes ||= OAuth::Scopes.new
322
327
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class Engine < Rails::Engine
3
5
  initializer "doorkeeper.params.filter" do |app|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module Errors
3
5
  class DoorkeeperError < StandardError
@@ -36,7 +38,22 @@ module Doorkeeper
36
38
  end
37
39
  end
38
40
 
41
+ class BaseResponseError < DoorkeeperError
42
+ attr_reader :response
43
+
44
+ def initialize(response)
45
+ @response = response
46
+ end
47
+ end
48
+
39
49
  UnableToGenerateToken = Class.new(DoorkeeperError)
40
50
  TokenGeneratorNotFound = Class.new(DoorkeeperError)
51
+ NoOrmCleaner = Class.new(DoorkeeperError)
52
+
53
+ InvalidToken = Class.new BaseResponseError
54
+ TokenExpired = Class.new InvalidToken
55
+ TokenRevoked = Class.new InvalidToken
56
+ TokenUnknown = Class.new InvalidToken
57
+ TokenForbidden = Class.new InvalidToken
41
58
  end
42
59
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module Grape
3
5
  class AuthorizationDecorator < SimpleDelegator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'doorkeeper/grape/authorization_decorator'
2
4
 
3
5
  module Doorkeeper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Define methods that can be called in any controller that inherits from
2
4
  # Doorkeeper::ApplicationMetalController or Doorkeeper::ApplicationController
3
5
  module Doorkeeper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module AccessGrantMixin
3
5
  extend ActiveSupport::Concern
@@ -42,8 +44,8 @@ module Doorkeeper
42
44
  def revoke_all_for(application_id, resource_owner, clock = Time)
43
45
  where(application_id: application_id,
44
46
  resource_owner_id: resource_owner.id,
45
- revoked_at: nil).
46
- update_all(revoked_at: clock.now.utc)
47
+ revoked_at: nil)
48
+ .update_all(revoked_at: clock.now.utc)
47
49
  end
48
50
 
49
51
  # Implements PKCE code_challenge encoding without base64 padding as described in the spec.
@@ -78,7 +80,7 @@ module Doorkeeper
78
80
  #
79
81
  # urlsafe_encode64(bin)
80
82
  # Returns the Base64-encoded version of bin. This method complies with
81
- # Base 64 Encoding with URL and Filename Safe Alphabet in RFC 4648.
83
+ # "Base 64 Encoding with URL and Filename Safe Alphabet" in RFC 4648.
82
84
  # The alphabet uses '-' instead of '+' and '_' instead of '/'.
83
85
 
84
86
  # @param code_verifier [#to_s] a one time use value (any object that responds to `#to_s`)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module AccessTokenMixin
3
5
  extend ActiveSupport::Concern
@@ -47,11 +49,11 @@ module Doorkeeper
47
49
  def revoke_all_for(application_id, resource_owner, clock = Time)
48
50
  where(application_id: application_id,
49
51
  resource_owner_id: resource_owner.id,
50
- revoked_at: nil).
51
- update_all(revoked_at: clock.now.utc)
52
+ revoked_at: nil)
53
+ .update_all(revoked_at: clock.now.utc)
52
54
  end
53
55
 
54
- # Looking for not expired Access Token with a matching set of scopes
56
+ # Looking for not revoked Access Token with a matching set of scopes
55
57
  # that belongs to specific Application and Resource Owner.
56
58
  #
57
59
  # @param application [Doorkeeper::Application]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module ApplicationMixin
3
5
  extend ActiveSupport::Concern
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module Models
3
5
  module Accessible
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module Models
3
5
  module Expirable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module Models
3
5
  module Orderable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module Models
3
5
  module Ownership
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module Models
3
5
  module Revocable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module Models
3
5
  module Scopes
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  module Authorization
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  module Authorization
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  module Authorization
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rack/utils'
2
4
 
3
5
  module Doorkeeper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  class AuthorizationCodeRequest < BaseRequest
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  class BaseRequest
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  class BaseResponse
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  class Client
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  class Client
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  class ClientCredentialsRequest < BaseRequest
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  class ClientCredentialsRequest < BaseRequest
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  class ClientCredentialsRequest < BaseRequest
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  class ClientCredentialsRequest < BaseRequest
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module OAuth
3
5
  class CodeRequest