doorkeeper 5.8.2 → 5.9.9

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -3
  3. data/README.md +2 -3
  4. data/app/controllers/doorkeeper/authorizations_controller.rb +38 -4
  5. data/app/controllers/doorkeeper/authorized_applications_controller.rb +23 -0
  6. data/app/controllers/doorkeeper/tokens_controller.rb +7 -9
  7. data/app/views/doorkeeper/applications/show.html.erb +5 -5
  8. data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
  9. data/app/views/doorkeeper/authorizations/show.html.erb +1 -1
  10. data/config/locales/en.yml +12 -11
  11. data/lib/doorkeeper/config/validations.rb +2 -2
  12. data/lib/doorkeeper/config.rb +31 -8
  13. data/lib/doorkeeper/engine.rb +2 -4
  14. data/lib/doorkeeper/errors.rb +15 -2
  15. data/lib/doorkeeper/helpers/controller.rb +7 -4
  16. data/lib/doorkeeper/models/access_grant_mixin.rb +10 -6
  17. data/lib/doorkeeper/models/access_token_mixin.rb +30 -13
  18. data/lib/doorkeeper/models/concerns/expiration_time_sql_math.rb +8 -0
  19. data/lib/doorkeeper/models/concerns/polymorphic_resource_owner.rb +0 -1
  20. data/lib/doorkeeper/models/concerns/revocable.rb +8 -1
  21. data/lib/doorkeeper/models/concerns/write_to_primary.rb +57 -0
  22. data/lib/doorkeeper/oauth/authorization/code.rb +3 -1
  23. data/lib/doorkeeper/oauth/authorization_code_request.rb +1 -0
  24. data/lib/doorkeeper/oauth/client/credentials.rb +58 -6
  25. data/lib/doorkeeper/oauth/client_credentials/creator.rb +7 -3
  26. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +1 -1
  27. data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -0
  28. data/lib/doorkeeper/oauth/error_response.rb +21 -1
  29. data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -7
  30. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +14 -0
  31. data/lib/doorkeeper/oauth/pre_authorization.rb +27 -0
  32. data/lib/doorkeeper/oauth/refresh_token_request.rb +19 -7
  33. data/lib/doorkeeper/oauth/scopes.rb +3 -2
  34. data/lib/doorkeeper/oauth/token.rb +95 -2
  35. data/lib/doorkeeper/oauth/token_introspection.rb +7 -3
  36. data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +1 -0
  37. data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +25 -7
  38. data/lib/doorkeeper/orm/active_record/mixins/application.rb +6 -0
  39. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +5 -1
  40. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +10 -2
  41. data/lib/doorkeeper/orm/active_record.rb +8 -12
  42. data/lib/doorkeeper/rails/routes.rb +1 -1
  43. data/lib/doorkeeper/request.rb +19 -7
  44. data/lib/doorkeeper/version.rb +2 -2
  45. data/lib/doorkeeper.rb +14 -0
  46. data/lib/generators/doorkeeper/remove_applications_secret_not_null_constraint_generator.rb +2 -2
  47. data/lib/generators/doorkeeper/templates/initializer.rb +28 -2
  48. metadata +5 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de574cec8c17af2fd1026081acc0bf592c71ecbf947d92546df6b4d48ce3b5ce
4
- data.tar.gz: eb282ce352bbd4491014b753535ff24e804ca801e02aef8a6ded3f7ca5951e64
3
+ metadata.gz: 3c4d0c4d775062d003452c97290c5fb4308812e17590946b9f8db9922e40f9d7
4
+ data.tar.gz: 7af434e11413a59e94cf12edd6ddcb088940110fabbd1174f0bacb2869a254da
5
5
  SHA512:
6
- metadata.gz: 68b668d79eb5532cb4dbe660eb26269d67eb545b5dbd12bae15c087752c7e5447e1f60326725c0d838189a746de5718e8644605dcdd946d4f2cf29a556297369
7
- data.tar.gz: 8ad2d79f707129abd0787710cc86ee563af9887f986dec03edc396c691ffb26e18279b3693bc15658d059e78dd7dc2ce3093a137c03bb16e7858832d9e80c368
6
+ metadata.gz: 1029aa2d0ff981b3d114f656f5b8d17308a946edd9466e7fe93d93fa5b6d1ba3c6873ba6cf628eab86ccb2f50b14507f272d61a0af829f2184963908941bb91c
7
+ data.tar.gz: 5b474f0a07ba2785acdbadca5d874a0b9e50955bebd0318499f84710cb06b0d1e8d58419ac4b889045e504011ddc88398ffea0c345434df291f0b43cf60fb3d2
data/CHANGELOG.md CHANGED
@@ -5,9 +5,77 @@ upgrade guides.
5
5
 
6
6
  User-visible changes worth mentioning.
7
7
 
8
- ## main
8
+ ## 5.9.9
9
9
 
10
- Add your entry here.
10
+ - Fix: `AuthorizedApplicationsController` now answers `401 Unauthorized` instead of running with a `nil` resource owner, which listed and revoked every token that has no resource owner — the ones the client credentials flow issues. Affected host applications are those whose `resource_owner_authenticator` answers `nil` without halting the request itself; the generated initializer's example redirects and is not affected.
11
+ - Fix: `AuthorizationsController#destroy` now validates the client and redirect URI before producing the deny response, and renders — never redirects — when validation fails. Previously the deny path performed no OAuth-layer validation at all, allowing an open redirect to an attacker-controlled origin with the OAuth `state` attached. Also reject unregistered `response_type` values on the authorization endpoint rather than resolving them through the `constantize` fallback.
12
+ - Fix: refuse redirect URIs with a script scheme (`javascript`, `vbscript`, `data`) both when an application is registered and at authorization time, regardless of `forbid_redirect_uri`. Such a URI is never a legitimate redirection endpoint, and with `response_mode=form_post` it became the action of the auto-submitting form the authorization server renders on its own origin. Already stored records with such a URI are now refused with `invalid_redirect_uri` before the consent screen is shown.
13
+
14
+ ## 5.9.8
15
+
16
+ - [#1938] Fix: a request body ActionDispatch cannot parse (malformed JSON under a JSON content type, say) no longer raises `ActionDispatch::Http::Parameters::ParseError` out of `Doorkeeper::OAuth::Token.from_request` and `doorkeeper_token`. Since 5.9.7 the RFC 6750 §2 multi-method check read the body on every request, so such a request raised even when it carried a valid Bearer header. The body is now treated as carrying no token, the same way ActionDispatch's own `#filtered_parameters` treats that error.
17
+
18
+ ## 5.9.7
19
+
20
+ - Refuse requests that transmit an access token by more than one method (RFC 6750 §2), instead of silently authorizing with the first configured `access_token_methods` entry that matched and discarding the other tokens. Such a request now fails closed as carrying no usable token (401 `invalid_token`); no calling contract changes. The form-encoded body (§2.2) and the URI query (§2.3) count as two methods even though Rails and Rack merge them into a single `params` hash. The same token repeated across two methods is refused too — §2 forbids the second method, not a disagreement between the two — and a custom callable extractor in `access_token_methods` keeps the historical first-wins behavior and is never invoked more than once. (The strict `invalid_request` (400) answer §3.1 prescribes ships with Doorkeeper 6.0.)
21
+ - [#1925] Internal: pin the development dependency on `json` below 3.0. json 3 removed the positional options Hash from `JSON.parse` and the `quirks_mode` option from `JSON.generate`, both of which Active Support still uses, so the suite could not run on any supported Rails version.
22
+
23
+ ## 5.9.6
24
+
25
+ - Reject requests that present more than one client identity (e.g. an `Authorization: Basic` header for one client and a `client_id` parameter naming another) with an `invalid_request` error, instead of authenticating the first extracted identity and silently discarding the other one. A `client_id` sent alongside another authentication method keeps working when it identifies the same client (RFC 7521 §4.2). Like the RFC 6749 §2.3 check released in 5.9.5, this validation does not apply when `client_credentials` is configured with a callable extractor, since the credentials the remaining extractors would return are never evaluated — the `client_credentials` option documents that now.
26
+
27
+ ## 5.9.5
28
+
29
+ - Reject requests that authenticate the client with more than one method (RFC 6749 §2.3) with an `invalid_request` error, instead of silently authenticating with the first method that matched and discarding the other credentials.
30
+ - [#1853] Fix `reuse_access_token` reusing a token that was created with `custom_access_token_attributes` values when the new request doesn't specify any custom attributes. Such requests now only match tokens without custom attributes.
31
+
32
+ ## 5.9.3
33
+
34
+ - [#1834] Fix default `allow_token_introspection` returning `false` when a custom `application_class` is configured. The default proc compared application objects with `==`, which fails when the authorized client and the introspected token's application are resolved as different classes (e.g. a base `Doorkeeper::Application` vs. a configured subclass) even though they reference the same record. It now compares application ids instead.
35
+ - [#1832] Fix confusing `belongs_to :owner` side effect: `Doorkeeper::Models::Ownership` is now included only when `enable_application_owner?` is set (read at include time), so models no longer expose a misleading `owner` association/reflection when the application owner feature is disabled and the schema lacks the owner columns.
36
+
37
+ ## 5.9.2
38
+
39
+ - [#1822][#1823][#1825] Update Rubocop config, auto-corrections and codebase cleanup.
40
+ - [#1830] Fix `NameError: uninitialized constant ApplicationRecord` on `rails db:seed` (and other non-eager-loading flows) caused by `on_load(:active_record)` firing re-entrantly during `ApplicationRecord` autoload. The orm hooks no longer depend on `ActiveSupport.on_load(:active_record)`; model concerns (`Ownership`, `PolymorphicResourceOwner::ForAccessGrant`, `PolymorphicResourceOwner::ForAccessToken`) are now wired up from each `Mixins::*` `included` block, which fires at parent-class autoload time — after `Doorkeeper.configure` has applied user settings and without re-entering the AR load chain.
41
+ - **Upgrade note**: fully custom model classes that don't include `Doorkeeper::Orm::ActiveRecord::Mixins::{Application,AccessToken,AccessGrant}` will no longer auto-receive `Ownership` / `PolymorphicResourceOwner` concerns (previously injected by `run_orm_hooks` via the configured class name). Either inherit from the Doorkeeper default model, include the corresponding `Mixins::*` module, or `include` the concerns directly.
42
+
43
+ ## 5.9.1
44
+
45
+ - [#1781] Honor `handle_auth_errors :raise` in `AuthorizationsController#authorize_response`
46
+ - [#1795] Fix: detailed error 'insufficient_scope' in protected resources 403s
47
+ - [#1797] Fix `doorkeeper:db:cleanup` rake task failure on PostgreSQL
48
+ - [#1800] Set `@grant_type` in `ClientCredentialsRequest` and `RefreshTokenRequest` constructors so `request.grant_type` returns
49
+ the correct value in hooks like `before_successful_strategy_response`.
50
+ - [#1802] Fix `filter_parameters` not applied when `Doorkeeper.configure` is called inside to_prepare.
51
+ - [#1804] Use `ActiveSupport.on_load(:active_record)` in ORM hooks to prevent loading ActiveRecord models too early
52
+ - [#1806] Fix token revocation bypass for public clients (RFC 7009)
53
+ - [#1815] Expose `current_resource_owner` as a view helper in `Doorkeeper::ApplicationController`.
54
+ - [#1818] Fix token introspection returning `exp: 0` for non-expiring tokens.
55
+ - [#1784] Remove hardcoded colons from view templates, move punctuation to i18n translation strings.
56
+
57
+ **[IMPORTANT]**: if you have customized Doorkeeper views (`authorizations/new`, `authorizations/show`,
58
+ `applications/show`) or overridden the default `en.yml` translations, you may need to update them.
59
+ Colons are no longer hardcoded in the views — they are now part of the translation strings.
60
+ Update the [doorkeeper-i18n](https://github.com/doorkeeper-gem/doorkeeper-i18n) gem to get the
61
+ updated translations for all locales.
62
+ - [#1820] Remove dead wildcard presence check in `Scopes#dynamic_scope_match?` (internal cleanup, no behavior change).
63
+ - [#1822] Update Rubocop config, auto-corrections.
64
+ - [#1823] Update Rubocop config, part 2.
65
+ - [#1825] Update Rubocop config, part 3.
66
+ - [#1821] Fix noisy `Could not find command "no_previous_refresh_token_column?"` Thor output during the
67
+ `PreviousRefreshTokenGenerator` spec by stubbing the underlying DB column check instead of the generator's
68
+ private method (test-only change).
69
+
70
+ ## 5.9.0
71
+
72
+ - [#1791] Add support for Rails read replicas with automatic role switching via `enable_multiple_database_roles` configuration option
73
+ - [#1792] Consider expires_in when clear expired tokens with StaleRecordsCleaner.
74
+ - [#1790] Fix race condition in refresh token revocation check by moving InvalidGrantReuse check inside the lock block
75
+ - [#1788] Fix regex for basic auth to be case-insensitive
76
+ - [#1775] Fix Applications Secret Not Null Constraint generator
77
+ - [#1779] Only lock previous access token model when creating a new token from its refresh token if revoke_previous_refresh_token_on_use is false
78
+ - [#1778] Ensure that token revocation is idempotent by checking that that token has not already been revoked before revoking.
11
79
 
12
80
  ## 5.8.2
13
81
 
@@ -31,7 +99,7 @@ Add your entry here.
31
99
  - [#1712] Add `Pragma: no-cache` to token response
32
100
  - [#1726] Refactor token introspection class.
33
101
  - [#1727] Allow to set null secret value for Applications if they are public.
34
- - [#1735] Add `pkce_code_challenge_methods` config option.
102
+ - [#1735] Add `pkce_code_challenge_methods` config option.
35
103
 
36
104
  ## 5.7.1
37
105
 
data/README.md CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/doorkeeper.svg)](https://rubygems.org/gems/doorkeeper)
4
4
  [![CI](https://github.com/doorkeeper-gem/doorkeeper/actions/workflows/ci.yml/badge.svg)](https://github.com/doorkeeper-gem/doorkeeper/actions/workflows/ci.yml)
5
- [![Code Climate](https://codeclimate.com/github/doorkeeper-gem/doorkeeper.svg)](https://codeclimate.com/github/doorkeeper-gem/doorkeeper)
5
+ [![Maintainability](https://qlty.sh/gh/doorkeeper-gem/projects/doorkeeper/maintainability.svg)](https://qlty.sh/gh/doorkeeper-gem/projects/doorkeeper)
6
6
  [![Coverage Status](https://coveralls.io/repos/github/doorkeeper-gem/doorkeeper/badge.svg?branch=main)](https://coveralls.io/github/doorkeeper-gem/doorkeeper?branch=main)
7
- [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
8
- [![GuardRails badge](https://badges.guardrails.io/doorkeeper-gem/doorkeeper.svg?token=66768ce8f6995814df81f65a2cff40f739f688492704f973e62809e15599bb62)](https://dashboard.guardrails.io/default/gh/doorkeeper-gem/doorkeeper)
7
+ [![GuardRails badge](https://api.guardrails.io/v2/badges/21183?token=66768ce8f6995814df81f65a2cff40f739f688492704f973e62809e15599bb62)](https://dashboard.guardrails.io/gh/doorkeeper-gem/repos/21183)
9
8
  [![Dependabot](https://img.shields.io/badge/dependabot-enabled-success.svg)](https://dependabot.com)
10
9
 
11
10
  Doorkeeper is a gem (Rails engine) that makes it easy to introduce OAuth 2 provider
@@ -16,7 +16,13 @@ module Doorkeeper
16
16
  redirect_or_render(authorize_response)
17
17
  end
18
18
 
19
+ # The deny path answers a request the client sent, so it is subject to the
20
+ # same client and redirect URI validation as #create: without it an
21
+ # unregistered redirect_uri was honoured and the user-agent redirected to
22
+ # it, carrying the OAuth `state` to an origin of the caller's choosing.
19
23
  def destroy
24
+ return if refuse_invalid_client?
25
+
20
26
  redirect_or_render(authorization.deny)
21
27
  rescue Doorkeeper::Errors::InvalidTokenStrategy => e
22
28
  error_response = get_error_response_from_exception(e)
@@ -45,13 +51,37 @@ module Doorkeeper
45
51
 
46
52
  if Doorkeeper.configuration.redirect_on_errors? && pre_auth.error_response.redirectable?
47
53
  redirect_or_render(pre_auth.error_response)
48
- elsif Doorkeeper.configuration.api_only
49
- render json: pre_auth.error_response.body, status: pre_auth.error_response.status
50
54
  else
51
- render :error, locals: { error_response: pre_auth.error_response }, status: pre_auth.error_response.status
55
+ render_error_response(pre_auth.error_response)
56
+ end
57
+ end
58
+
59
+ def render_error_response(error_response)
60
+ if Doorkeeper.configuration.api_only
61
+ render json: error_response.body, status: error_response.status
62
+ else
63
+ render :error, locals: { error_response: error_response }, status: error_response.status
52
64
  end
53
65
  end
54
66
 
67
+ # Renders the error when the request's client_id or redirect_uri is missing
68
+ # or invalid, and answers whether the request was refused. Errors are
69
+ # rendered, never redirected, regardless of `handle_auth_errors :redirect`:
70
+ # no failure this check can produce leaves a redirect target worth
71
+ # trusting. Either the client failed first, so the redirect URI was never
72
+ # reached, or the redirect URI is itself the invalid one - and RFC 6749
73
+ # Section 3.1.2.4 forbids redirecting the user-agent to an invalid
74
+ # redirection URI.
75
+ def refuse_invalid_client?
76
+ return false if pre_auth.client_valid?
77
+
78
+ error_response = pre_auth.error_response
79
+ error_response.raise_exception! if Doorkeeper.config.raise_on_errors?
80
+
81
+ render_error_response(error_response)
82
+ true
83
+ end
84
+
55
85
  def can_authorize_response?
56
86
  Doorkeeper.config.custom_access_token_attributes.empty? && pre_auth.client.application.confidential? && matching_token?
57
87
  end
@@ -131,7 +161,11 @@ module Doorkeeper
131
161
 
132
162
  def authorize_response
133
163
  @authorize_response ||= begin
134
- return pre_auth.error_response unless pre_auth.authorizable?
164
+ unless pre_auth.authorizable?
165
+ response = pre_auth.error_response
166
+ response.raise_exception! if Doorkeeper.config.raise_on_errors?
167
+ return response
168
+ end
135
169
 
136
170
  context = build_context(pre_auth: pre_auth)
137
171
  before_successful_authorization(context)
@@ -3,6 +3,7 @@
3
3
  module Doorkeeper
4
4
  class AuthorizedApplicationsController < Doorkeeper::ApplicationController
5
5
  before_action :authenticate_resource_owner!
6
+ before_action :validate_resource_owner
6
7
 
7
8
  def index
8
9
  @applications = Doorkeeper.config.application_model.authorized_for(current_resource_owner)
@@ -29,5 +30,27 @@ module Doorkeeper
29
30
  format.json { head :no_content }
30
31
  end
31
32
  end
33
+
34
+ private
35
+
36
+ # `authenticate_resource_owner!` hands the request to the host
37
+ # application's `resource_owner_authenticator` block, which is expected to
38
+ # halt the request itself — redirect to a sign-in page, raise, render —
39
+ # when nobody is signed in. A block that merely answers nil halts nothing:
40
+ # the library default (no block configured) logs a warning and answers
41
+ # nil, and so does any block written as a bare lookup such as
42
+ # `User.find_by(id: session[:user_id])`.
43
+ #
44
+ # Both actions here scope their work to `current_resource_owner`, and a
45
+ # nil owner is not "no scope" — it is the scope of the records that have
46
+ # no resource owner, which is what the client credentials flow issues.
47
+ # #index would list every application holding one and #destroy would
48
+ # revoke them, for a caller that never authenticated. So refuse the
49
+ # request rather than treat "nobody" as an owner. Only this controller is
50
+ # guarded; `authenticate_resource_owner!` itself is left alone because
51
+ # AuthorizationsController shapes its own response around the owner.
52
+ def validate_resource_owner
53
+ head :unauthorized unless current_resource_owner
54
+ end
32
55
  end
33
56
  end
@@ -87,24 +87,22 @@ module Doorkeeper
87
87
  # credentials, in the case of a confidential client. The token being
88
88
  # revoked must also belong to the requesting client.
89
89
  #
90
- # Once a confidential client is authenticated, it must be authorized to
90
+ # Once a client is authenticated, it must be authorized to
91
91
  # revoke the provided access or refresh token. This ensures one client
92
92
  # cannot revoke another's tokens.
93
93
  #
94
- # Doorkeeper determines the client type implicitly via the presence of the
95
- # OAuth client associated with a given access or refresh token. Since public
96
- # clients authenticate the resource owner via "password" or "implicit" grant
97
- # types, they set the application_id as null (since the claim cannot be
98
- # verified).
94
+ # Doorkeeper checks token ownership for any token that has an
95
+ # application_id set. Tokens issued without a client (application_id
96
+ # is null) can be revoked without client authorization.
99
97
  #
100
98
  # https://datatracker.ietf.org/doc/html/rfc6749#section-2.1
101
99
  # https://datatracker.ietf.org/doc/html/rfc7009
102
100
  def authorized?
103
101
  # Token belongs to specific client, so we need to check if
104
102
  # authenticated client could access it.
105
- if token.application_id? && token.application.confidential?
106
- # We authorize client by checking token's application
107
- server.client && server.client.application == token.application
103
+ if token.application_id?
104
+ # We authorize client by comparing client and token application IDs
105
+ server.client && server.client.id == token.application_id
108
106
  else
109
107
  # Token was issued without client, authorization unnecessary
110
108
  true
@@ -4,10 +4,10 @@
4
4
 
5
5
  <div class="row">
6
6
  <div class="col-md-8">
7
- <h4><%= t('.application_id') %>:</h4>
7
+ <h4><%= t('.application_id') %></h4>
8
8
  <p><code class="bg-light" id="application_id"><%= @application.uid %></code></p>
9
9
 
10
- <h4><%= t('.secret') %>:</h4>
10
+ <h4><%= t('.secret') %></h4>
11
11
  <p>
12
12
  <code class="bg-light" id="secret">
13
13
  <% secret = flash[:application_secret].presence || @application.plaintext_secret %>
@@ -19,7 +19,7 @@
19
19
  </code>
20
20
  </p>
21
21
 
22
- <h4><%= t('.scopes') %>:</h4>
22
+ <h4><%= t('.scopes') %></h4>
23
23
  <p>
24
24
  <code class="bg-light" id="scopes">
25
25
  <% if @application.scopes.present? %>
@@ -30,10 +30,10 @@
30
30
  </code>
31
31
  </p>
32
32
 
33
- <h4><%= t('.confidential') %>:</h4>
33
+ <h4><%= t('.confidential') %></h4>
34
34
  <p><code class="bg-light" id="confidential"><%= @application.confidential? %></code></p>
35
35
 
36
- <h4><%= t('.callback_urls') %>:</h4>
36
+ <h4><%= t('.callback_urls') %></h4>
37
37
 
38
38
  <% if @application.redirect_uri.present? %>
39
39
  <table>
@@ -9,7 +9,7 @@
9
9
 
10
10
  <% if @pre_auth.scopes.count > 0 %>
11
11
  <div id="oauth-permissions">
12
- <p><%= t('.able_to') %>:</p>
12
+ <p><%= t('.able_to') %></p>
13
13
 
14
14
  <ul class="text-info">
15
15
  <% @pre_auth.scopes.each do |scope| %>
@@ -1,5 +1,5 @@
1
1
  <header class="page-header">
2
- <h1><%= t('.title') %>:</h1>
2
+ <h1><%= t('.title') %></h1>
3
3
  </header>
4
4
 
5
5
  <main role="main">
@@ -16,7 +16,7 @@ en:
16
16
  secured_uri: 'must be an HTTPS/SSL URI.'
17
17
  forbidden_uri: 'is forbidden by the server.'
18
18
  scopes:
19
- not_match_configured: "doesn't match configured on the server."
19
+ not_match_configured: "doesn't match those configured on the server."
20
20
 
21
21
  doorkeeper:
22
22
  applications:
@@ -33,7 +33,7 @@ en:
33
33
  help:
34
34
  confidential: 'Application will be used where the client secret can be kept confidential. Native mobile apps and Single Page Apps are considered non-confidential.'
35
35
  redirect_uri: 'Use one line per URI'
36
- blank_redirect_uri: "Leave it blank if you configured your provider to use Client Credentials, Resource Owner Password Credentials or any other grant type that doesn't require redirect URI."
36
+ blank_redirect_uri: "Leave it blank if you configured your provider to use Client Credentials, Resource Owner Password Credentials or any other grant type that doesn't require a redirect URI."
37
37
  scopes: 'Separate scopes with spaces. Leave blank to use the default scopes.'
38
38
  edit:
39
39
  title: 'Edit application'
@@ -51,12 +51,12 @@ en:
51
51
  title: 'New Application'
52
52
  show:
53
53
  title: 'Application: %{name}'
54
- application_id: 'UID'
55
- secret: 'Secret'
54
+ application_id: 'UID:'
55
+ secret: 'Secret:'
56
56
  secret_hashed: 'Secret hashed'
57
- scopes: 'Scopes'
58
- confidential: 'Confidential'
59
- callback_urls: 'Callback urls'
57
+ scopes: 'Scopes:'
58
+ confidential: 'Confidential:'
59
+ callback_urls: 'Callback URLs:'
60
60
  actions: 'Actions'
61
61
  not_defined: 'Not defined'
62
62
 
@@ -69,9 +69,9 @@ en:
69
69
  new:
70
70
  title: 'Authorization required'
71
71
  prompt: 'Authorize %{client_name} to use your account?'
72
- able_to: 'This application will be able to'
72
+ able_to: 'This application will be able to:'
73
73
  show:
74
- title: 'Authorization code'
74
+ title: 'Authorization code:'
75
75
  form_post:
76
76
  title: 'Submit this form'
77
77
 
@@ -95,9 +95,10 @@ en:
95
95
  invalid_request:
96
96
  unknown: 'The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.'
97
97
  missing_param: 'Missing required parameter: %{value}.'
98
- request_not_authorized: 'Request need to be authorized. Required parameter for authorizing request is missing or invalid.'
98
+ request_not_authorized: 'Request needs to be authorized. Required parameter for authorizing the request is missing or invalid.'
99
99
  invalid_code_challenge: 'Code challenge is required.'
100
- invalid_redirect_uri: "The requested redirect uri is malformed or doesn't match client redirect URI."
100
+ multiple_client_auth_methods: 'The request utilizes more than one mechanism for authenticating the client.'
101
+ invalid_redirect_uri: "The requested redirect URI is malformed or doesn't match the client redirect URI."
101
102
  unauthorized_client: 'The client is not authorized to perform this request using this method.'
102
103
  access_denied: 'The resource owner or authorization server denied the request.'
103
104
  invalid_scope: 'The requested scope is invalid, unknown, or malformed.'
@@ -51,14 +51,14 @@ module Doorkeeper
51
51
  end
52
52
 
53
53
  def validate_pkce_code_challenge_methods
54
- return if pkce_code_challenge_methods.all? {|method| method =~ /^plain$|^S256$/ }
54
+ return if pkce_code_challenge_methods.all? { |method| method =~ /^plain$|^S256$/ }
55
55
 
56
56
  ::Rails.logger.warn(
57
57
  "[DOORKEEPER] You have configured an invalid value for pkce_code_challenge_methods option. " \
58
58
  "It will be set to default ['plain', 'S256']",
59
59
  )
60
60
 
61
- @pkce_code_challenge_methods = ['plain', 'S256']
61
+ @pkce_code_challenge_methods = ["plain", "S256"]
62
62
  end
63
63
  end
64
64
  end
@@ -38,7 +38,7 @@ module Doorkeeper
38
38
  # @param opts [Hash] the options to configure dynamic scopes
39
39
  def enable_dynamic_scopes(opts = {})
40
40
  @config.instance_variable_set(:@enable_dynamic_scopes, true)
41
- @config.instance_variable_set(:@dynamic_scopes_delimiter, opts[:delimiter] || ':')
41
+ @config.instance_variable_set(:@dynamic_scopes_delimiter, opts[:delimiter] || ":")
42
42
  end
43
43
 
44
44
  # Define default access token scopes for your provider
@@ -69,6 +69,10 @@ module Doorkeeper
69
69
  # falls back to the `:client_id` and `:client_secret` params from the
70
70
  # `params` object.
71
71
  #
72
+ # NOTE: a list that includes a callable extractor opts out of the RFC 6749
73
+ # §2.3 validation applied to the symbol extractors — see
74
+ # +Doorkeeper::OAuth::Client::Credentials.from_request+.
75
+ #
72
76
  # @param methods [Array] Define client credentials
73
77
  def client_credentials(*methods)
74
78
  @config.instance_variable_set(:@client_credentials_methods, methods)
@@ -99,7 +103,23 @@ module Doorkeeper
99
103
  @config.instance_variable_set(:@reuse_access_token, true)
100
104
  end
101
105
 
102
- # Choose to use the url path for native autorization codes
106
+ # Enable support for multiple database configurations with read replicas.
107
+ # When enabled, wraps database write operations to ensure they use the primary
108
+ # (writable) database when automatic role switching is enabled.
109
+ #
110
+ # For ActiveRecord (Rails 6.1+), this uses `ActiveRecord::Base.connected_to(role: :writing)`.
111
+ # Other ORM extensions can implement their own primary database targeting logic.
112
+ #
113
+ # This prevents `ActiveRecord::ReadOnlyError` when using read replicas with Rails
114
+ # automatic role switching. Enable this if your application uses multiple databases
115
+ # with automatic role switching for read replicas.
116
+ #
117
+ # See: https://guides.rubyonrails.org/active_record_multiple_databases.html#activating-automatic-role-switching
118
+ def enable_multiple_database_roles
119
+ @config.instance_variable_set(:@enable_multiple_database_roles, true)
120
+ end
121
+
122
+ # Choose to use the url path for native autorization codes
103
123
  # Enabling this flag sets the authorization code response route for
104
124
  # native redirect uris to oauth/authorize/<code>. The default is
105
125
  # oauth/authorize/native?code=<code>.
@@ -309,7 +329,9 @@ module Doorkeeper
309
329
  option :allow_grant_flow_for_client, default: ->(_grant_flow, _client) { true }
310
330
 
311
331
  # Allows to forbid specific Application redirect URI's by custom rules.
312
- # Doesn't forbid any URI by default.
332
+ # Doesn't forbid any URI by default. Redirect URIs with a script scheme
333
+ # (`javascript`, `vbscript`, `data`) are always rejected, regardless of
334
+ # this option.
313
335
  #
314
336
  # @param forbid_redirect_uri [Proc] Block or any object respond to #call
315
337
  #
@@ -428,15 +450,16 @@ module Doorkeeper
428
450
  option :allow_token_introspection,
429
451
  default: (lambda do |token, authorized_client, authorized_token|
430
452
  if authorized_token
431
- authorized_token.application == token&.application
453
+ authorized_token.application_id == token&.application_id
432
454
  elsif token&.application
433
- authorized_client == token.application
455
+ authorized_client.id == token.application_id
434
456
  else
435
457
  true
436
458
  end
437
459
  end)
438
460
 
439
461
  attr_reader :reuse_access_token,
462
+ :enable_multiple_database_roles,
440
463
  :token_secret_fallback_strategy,
441
464
  :application_secret_fallback_strategy
442
465
 
@@ -575,7 +598,7 @@ module Doorkeeper
575
598
 
576
599
  def pkce_code_challenge_methods_supported
577
600
  return [] unless access_grant_model.pkce_supported?
578
-
601
+
579
602
  pkce_code_challenge_methods
580
603
  end
581
604
 
@@ -616,10 +639,10 @@ module Doorkeeper
616
639
  def deprecated_token_grant_types_resolver
617
640
  @deprecated_token_grant_types ||= calculate_token_grant_types
618
641
  end
619
-
642
+
620
643
  def native_authorization_code_route
621
644
  @use_url_path_for_native_authorization = false unless defined?(@use_url_path_for_native_authorization)
622
- @use_url_path_for_native_authorization ? '/:code' : '/native'
645
+ @use_url_path_for_native_authorization ? "/:code" : "/native"
623
646
  end
624
647
 
625
648
  # [NOTE]: deprecated and will be removed soon
@@ -3,10 +3,8 @@
3
3
  module Doorkeeper
4
4
  class Engine < Rails::Engine
5
5
  initializer "doorkeeper.params.filter", after: :load_config_initializers do |app|
6
- if Doorkeeper.configured?
7
- parameters = %w[client_secret authentication_token access_token refresh_token]
8
- parameters << "code" if Doorkeeper.config.grant_flows.include?("authorization_code")
9
- app.config.filter_parameters << /^(#{Regexp.union(parameters)})$/
6
+ app.config.to_prepare do
7
+ Doorkeeper.setup_filter_parameters
10
8
  end
11
9
  end
12
10
 
@@ -24,6 +24,19 @@ module Doorkeeper
24
24
  end
25
25
  end
26
26
 
27
+ # Raised when a request uses more than one client authentication method,
28
+ # which RFC 6749 §2.3 explicitly forbids ("The client MUST NOT use more
29
+ # than one authentication method in each request").
30
+ class MultipleClientAuthMethods < DoorkeeperError
31
+ def type
32
+ :invalid_request
33
+ end
34
+
35
+ def reason
36
+ :multiple_client_auth_methods
37
+ end
38
+ end
39
+
27
40
  class MissingRequiredParameter < DoorkeeperError
28
41
  attr_reader :missing_param
29
42
 
@@ -45,7 +58,7 @@ module Doorkeeper
45
58
  end
46
59
 
47
60
  def self.name_for_response
48
- self.name.demodulize.underscore.to_sym
61
+ name.demodulize.underscore.to_sym
49
62
  end
50
63
  end
51
64
 
@@ -54,7 +67,7 @@ module Doorkeeper
54
67
  challenge_methods = Doorkeeper.config.pkce_code_challenge_methods_supported
55
68
  {
56
69
  challenge_methods: challenge_methods.join(", "),
57
- count: challenge_methods.length
70
+ count: challenge_methods.length,
58
71
  }
59
72
  end
60
73
  end
@@ -7,6 +7,10 @@ module Doorkeeper
7
7
  # Rails controller helpers.
8
8
  #
9
9
  module Controller
10
+ def self.included(base)
11
+ base.helper_method :current_resource_owner if base.respond_to?(:helper_method)
12
+ end
13
+
10
14
  private
11
15
 
12
16
  # :doc:
@@ -18,9 +22,7 @@ module Doorkeeper
18
22
  def current_resource_owner
19
23
  return @current_resource_owner if defined?(@current_resource_owner)
20
24
 
21
- @current_resource_owner ||= begin
22
- instance_eval(&Doorkeeper.config.authenticate_resource_owner)
23
- end
25
+ @current_resource_owner ||= instance_eval(&Doorkeeper.config.authenticate_resource_owner)
24
26
  end
25
27
 
26
28
  def resource_owner_from_credentials
@@ -54,7 +56,8 @@ module Doorkeeper
54
56
  OAuth::InvalidRequestResponse.new(
55
57
  name: exception.type,
56
58
  state: params[:state],
57
- missing_param: exception.missing_param,
59
+ missing_param: exception.try(:missing_param),
60
+ reason: exception.try(:reason),
58
61
  )
59
62
  else
60
63
  OAuth::ErrorResponse.new(name: exception.type, state: params[:state])
@@ -12,6 +12,8 @@ module Doorkeeper
12
12
  include Models::SecretStorable
13
13
  include Models::Scopes
14
14
  include Models::ResourceOwnerable
15
+ include Models::Concerns::WriteToPrimary
16
+ include Models::ExpirationTimeSqlMath
15
17
 
16
18
  # Never uses PKCE if PKCE migrations were not generated
17
19
  def uses_pkce?
@@ -40,12 +42,14 @@ module Doorkeeper
40
42
  # instance of the Resource Owner model or it's ID
41
43
  #
42
44
  def revoke_all_for(application_id, resource_owner, clock = Time)
43
- by_resource_owner(resource_owner)
44
- .where(
45
- application_id: application_id,
46
- revoked_at: nil,
47
- )
48
- .update_all(revoked_at: clock.now.utc)
45
+ with_primary_role do
46
+ by_resource_owner(resource_owner)
47
+ .where(
48
+ application_id: application_id,
49
+ revoked_at: nil,
50
+ )
51
+ .update_all(revoked_at: clock.now.utc)
52
+ end
49
53
  end
50
54
 
51
55
  # Implements PKCE code_challenge encoding without base64 padding as described in the spec.