doorkeeper 5.9.3 → 6.0.0.beta1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -0
- data/README.md +1 -0
- data/app/controllers/doorkeeper/metadata_controller.rb +20 -0
- data/app/controllers/doorkeeper/tokens_controller.rb +10 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +6 -0
- data/config/locales/en.yml +1 -0
- data/lib/doorkeeper/client_authentication/credentials.rb +11 -0
- data/lib/doorkeeper/client_authentication/fallback_method.rb +19 -0
- data/lib/doorkeeper/client_authentication/legacy_callable.rb +46 -0
- data/lib/doorkeeper/client_authentication/method.rb +23 -0
- data/lib/doorkeeper/client_authentication/registry.rb +47 -0
- data/lib/doorkeeper/client_authentication.rb +93 -0
- data/lib/doorkeeper/config/option.rb +1 -1
- data/lib/doorkeeper/config/validations.rb +162 -1
- data/lib/doorkeeper/config.rb +114 -9
- data/lib/doorkeeper/errors.rb +14 -0
- data/lib/doorkeeper/helpers/controller.rb +2 -1
- data/lib/doorkeeper/models/access_token_mixin.rb +48 -8
- data/lib/doorkeeper/models/application_mixin.rb +14 -6
- data/lib/doorkeeper/models/concerns/secret_storable.rb +10 -1
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +11 -0
- data/lib/doorkeeper/oauth/authorization_code_request.rb +4 -1
- data/lib/doorkeeper/oauth/client.rb +18 -0
- data/lib/doorkeeper/oauth/client_authentication/client_secret_basic.rb +53 -0
- data/lib/doorkeeper/oauth/client_authentication/client_secret_post.rb +29 -0
- data/lib/doorkeeper/oauth/client_authentication/none.rb +32 -0
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -1
- data/lib/doorkeeper/oauth/code_response.rb +16 -2
- data/lib/doorkeeper/oauth/error_response.rb +11 -2
- data/lib/doorkeeper/oauth/metadata_response.rb +157 -0
- data/lib/doorkeeper/oauth/pre_authorization.rb +12 -5
- data/lib/doorkeeper/oauth/token_introspection.rb +27 -7
- data/lib/doorkeeper/orm/active_record/mixins/application.rb +2 -2
- data/lib/doorkeeper/rails/routes/mapping.rb +1 -0
- data/lib/doorkeeper/rails/routes.rb +6 -0
- data/lib/doorkeeper/request.rb +59 -0
- data/lib/doorkeeper/server.rb +5 -2
- data/lib/doorkeeper/version.rb +4 -4
- data/lib/doorkeeper.rb +8 -4
- data/lib/generators/doorkeeper/templates/initializer.rb +66 -6
- metadata +12 -2
- data/lib/doorkeeper/oauth/client/credentials.rb +0 -34
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 454edd4f496ec3750a0be3da7db728302d93b355c075d6aded28792c8a53b9a8
|
|
4
|
+
data.tar.gz: 8be2862ad184cb71e36a5b9d2747bfc5186fe8bf9c539b6d61fbe92d05a57e5c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3cb1367a63c3404a1dc79dd910265e5c189da7e8745b40c48f46e06d9b326f7a215760747c0273e28a51a26ff8e6447c376faf6a169d9f93cec84aac97191022
|
|
7
|
+
data.tar.gz: 3a3dc94969468b7ff5ef364876d068bf8fde231fcaeaa5ea6e43c207f7aafb236f02b5264b32678ad100788a1deb99caee79a3701cca1b4f79fd3a7f487865f1
|
data/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,46 @@ User-visible changes worth mentioning.
|
|
|
9
9
|
|
|
10
10
|
- Please add here
|
|
11
11
|
|
|
12
|
+
## 6.0.0.beta1
|
|
13
|
+
|
|
14
|
+
**Please make sure** you read the [Upgrade guides](https://github.com/doorkeeper-gem/doorkeeper/wiki/Migration-from-old-versions)
|
|
15
|
+
and changelog below before the update since this version includes breaking changes.
|
|
16
|
+
|
|
17
|
+
- [#1816] Fix: redirect `unauthorized_client` errors per RFC 6749 Section 4.1.2.1; validate redirect_uri before `client_supports_grant_flow` to prevent open redirect
|
|
18
|
+
- [#1867] Fix: use `access_denied` instead of `invalid_client` for `resource_owner_authorize_for_client` validation per RFC 6749 Section 4.1.2.1. `invalid_client` is a token endpoint error (Section 5.2), not an authorization endpoint error.
|
|
19
|
+
- [#1838] Add OAuth 2.0 Authorization Server Metadata endpoint (RFC 8414) served at `/.well-known/oauth-authorization-server`. The response is built from your Doorkeeper configuration and advertises the authorization, token, revocation and (when token introspection is enabled) introspection endpoints, supported scopes, response/grant types and PKCE code challenge methods. Two new config options are available: `issuer` (defaults to the request base URL) and `custom_metadata` (a Hash merged into the response, e.g. to advertise an OIDC `userinfo_endpoint`). The controller/response use the RFC 8414 "Metadata" naming so they don't collide with a future OpenID Connect Discovery (`.well-known/openid-configuration`) implementation. Endpoints disabled through `skip_controllers` are omitted from the response instead of raising a route-generation error.
|
|
20
|
+
- [#1839] Send client credentials in the request body (not the query string) in the token endpoint specs, per RFC 6749 §2.3.1. Test-only change: the `*_endpoint_url` helpers now return a path plus a matching `*_endpoint_params` builder so flow specs post credentials through the body.
|
|
21
|
+
- [#1840] Introduce a pluggable client authentication registry (RFC 6749 §2.3).
|
|
22
|
+
- New `client_authentication` config option declares which methods are accepted and in which order. Built-in strategies: `client_secret_basic`, `client_secret_post` and `none`.
|
|
23
|
+
- Custom strategies can be registered with `Doorkeeper::ClientAuthentication.register`.
|
|
24
|
+
- **[BREAKING]** Client credentials are no longer read from the query string — send them in the request body or via HTTP Basic. This applies to every endpoint that authenticates clients: token, revocation and introspection.
|
|
25
|
+
- **[BREAKING]** The `none` strategy rejects requests that carry a non-blank `Authorization` header. A common casualty is a public client POSTing to `/oauth/revoke` with a body `client_id` while still sending its `Authorization: Bearer <token>` header — drop the header from that request.
|
|
26
|
+
- **[BREAKING]** The `Doorkeeper::OAuth::Client::Credentials` class methods `.from_request`, `.from_basic` and `.from_params` are removed — extensions extracting credentials from a request should register a client authentication method instead.
|
|
27
|
+
- **Deprecated**: the `client_credentials` option — use `client_authentication` instead.
|
|
28
|
+
- **Deprecated**: the `Doorkeeper::OAuth::Client::Credentials` constant itself — it remains as an alias of `Doorkeeper::ClientAuthentication::Credentials` (the plain uid/secret struct).
|
|
29
|
+
- See the [Upgrade Guide](https://github.com/doorkeeper-gem/doorkeeper/wiki/Migration-from-old-versions) for detailed breaking changes, deprecations and migration steps.
|
|
30
|
+
- [#1841] Reject requests that use more than one client authentication method (RFC 6749 §2.3: "The client MUST NOT use more than one authentication method in each request") with an `invalid_request` error instead of silently using the first match. The request payload is validated against every registered method before the configured one is selected, so a client sending e.g. both Basic and body credentials is rejected even when only one of those methods is enabled. This applies to every endpoint that authenticates clients — token, revocation and introspection. Only real authentication mechanisms count: a bare `client_id` (the `none` method) is not a mechanism of its own, and deprecated `client_credentials` callable extractors never count towards the limit (they keep the historical first-extractor-wins selection).
|
|
31
|
+
- [#1842] **[BREAKING]** `force_pkce` now requires PKCE for all clients, including confidential ones, in line with the OAuth 2.0 Security BCP (RFC 9700) and OAuth 2.1. Previously confidential clients were exempt. If you enable `force_pkce` and have confidential clients that do not yet send a `code_challenge`/`code_verifier`, their authorization requests will start to be rejected.
|
|
32
|
+
- [#1845] Fix `NameError` when the config option DSL (`Doorkeeper::Config::Option`) is extended into a class that does not define `self.builder_class`. The guard raised `Doorkeeper::MissingConfigurationBuilderClass`, a constant that was never defined, so callers saw `uninitialized constant` instead of the intended message. The error is now defined as `Doorkeeper::Errors::MissingConfigurationBuilderClass` (a `DoorkeeperError`) and referenced correctly.
|
|
33
|
+
- [#1846] Document and pin with regression specs that a `scope` parameter sent to the token endpoint is ignored for the `authorization_code` grant (RFC 6749 §4.1.3 does not define one): the access token always inherits the scopes of the authorization grant, and the response reports the actual granted `scope`. No behavior change.
|
|
34
|
+
- [#1847] Fix `Doorkeeper.config.enabled_grant_flows` (and `calculate_grant_flows`) not listing the `refresh_token` grant flow when `use_refresh_token` is configured, so consumers (e.g. RFC 8414 metadata) no longer need to append it manually — the built-in metadata endpoint now relies on this too. The flow is no longer duplicated in `token_grant_flows` when `refresh_token` is also listed in `grant_flows` explicitly, a configuration-time warning is logged when `grant_flows` enables `refresh_token` without `use_refresh_token` (no refresh tokens would ever be issued), and the initializer template documents the flow.
|
|
35
|
+
- [#1848] Derive `token_endpoint_auth_methods_supported` in the RFC 8414 metadata response from the effective client authentication configuration (including a deprecated `client_credentials`-only setup) instead of hardcoding the default methods. Servers that customize `client_authentication` (including extension-registered methods like `private_key_jwt`) now see their metadata reflect what the server actually accepts; unregistered names are not advertised.
|
|
36
|
+
- [#1849] Support RFC 9207 (Authorization Server Issuer Identification): when `issuer` is configured, the `iss` parameter is added to the authorization responses redirected back to the client (successful and error responses alike) and `authorization_response_iss_parameter_supported` is advertised in the server metadata. Clients that parse the authorization redirect will start seeing the new `iss` parameter. A configured `issuer` that is not RFC-compliant (not an https URL, or containing a query/fragment) now logs a warning at boot, as does a path-bearing issuer, which RFC 8414 clients would not discover through Doorkeeper's root-only well-known metadata route.
|
|
37
|
+
- [#1850] Fix `reuse_access_token` returning a refresh token that doesn't match the request: token reuse now requires the candidate's refresh token presence to match what the request asks for, in both directions. A request that expects a refresh token (e.g. `use_refresh_token` enabled) no longer reuses a token issued without one (previously the refresh token was silently omitted), and a request that does not expect one no longer reuses a token that carries one (previously an unrequested refresh token was returned, reachable via a per-request `refresh_token_enabled` callable). The requirement participates in the token matching itself, so an older matching token that satisfies it is still reused; a fresh token is created only when none does. **API change for ORM extensions**: `matching_token_for` and `find_matching_token` now take an optional block (`&filter`) that a token must satisfy to count as a match — extensions overriding either method must accept the block and honor it (accept and yield).
|
|
38
|
+
- [#1851] Fix duplicate query parameter in the authorization callback when a client's registered `redirect_uri` already contains a parameter with the same name as a response parameter (e.g. `state`). The redirect query was merged with string keys on one side and symbol keys on the other, so a collision emitted the parameter twice (`?state=fixed&code=...&state=user`); the response parameter now overrides the registered one and appears exactly once. A blank response parameter (e.g. no `state` sent with the request) leaves the registered parameter untouched, per RFC 6749 §3.1.2.
|
|
39
|
+
- [#1852] Fix the `pkce_code_challenge_methods` config validator using line anchors (`^`/`$`) instead of string anchors (`\A`/`\z`), so a multi-line value such as `"plain\ngarbage"` passed validation and was retained as a (never-matching) challenge method instead of being rejected and reset to the default.
|
|
40
|
+
- [#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.
|
|
41
|
+
- [#1854] Fix the RFC 8414 metadata endpoint raising `ActionController::UrlGenerationError` (HTTP 500) when `use_doorkeeper` configures a custom controller whose namespace depth differs from `doorkeeper/metadata` (e.g. `controllers tokens: "custom_tokens"`).
|
|
42
|
+
- [#1855] Perform the fallback secret upgrade-on-access write (plain → hashed token or application secret) through the primary database role, so `enable_multiple_database_roles` setups no longer attempt the write on a read replica when the lookup happens in a request routed to the reading role.
|
|
43
|
+
- [#1857] Pin with regression specs that a `+` between scopes in a form-encoded token request is decoded as a space (so `scope=public+write` refreshes fine), while a percent-encoded literal `+` (`%2B`) names a single scope and is rejected when unknown, per RFC 6749 §3.3. Test-only change, closes [#1686].
|
|
44
|
+
- [#1859] Pin with regression specs that a refresh token bound to an expired access token can be revoked (fixed by [#1744]) and that the revoked refresh token is rejected at the token endpoint afterwards. Test-only change, closes [#1671].
|
|
45
|
+
- [#1860] Fix introspection of refresh tokens (RFC 7662): a refresh token bound to an expired access token now introspects as `active: true`, matching the token endpoint which still accepts it. The introspection response for a presented refresh token no longer includes the paired access token's `token_type` and `exp`. Fixes [#1858].
|
|
46
|
+
- [#1862] Document that with `reuse_access_token` enabled token matching considers only the application, resource owner, scopes and custom token attributes — separate authorization grants for the same combination intentionally share one access token — and pin the behavior with a regression spec. Docs/test-only change, closes [#1693].
|
|
47
|
+
- [#1864] Fix `custom_access_token_attributes` values being dropped when the authorization goes through the consent screen: the approve/deny forms now carry the custom attributes as hidden fields, and the pre-authorization JSON (`api_only` mode) includes them so custom consent UIs can send them back.
|
|
48
|
+
- [#1869] Improve test coverage
|
|
49
|
+
- [#1870] Fix: raise the intended `Doorkeeper::Errors::TokenGeneratorNotFound` / `UnableToGenerateToken` (instead of a confusing `NameError`) when `application_secret_generator` is misconfigured.
|
|
50
|
+
- Please add here
|
|
51
|
+
|
|
12
52
|
## 5.9.3
|
|
13
53
|
|
|
14
54
|
- [#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.
|
|
@@ -27,6 +67,7 @@ User-visible changes worth mentioning.
|
|
|
27
67
|
- [#1797] Fix `doorkeeper:db:cleanup` rake task failure on PostgreSQL
|
|
28
68
|
- [#1800] Set `@grant_type` in `ClientCredentialsRequest` and `RefreshTokenRequest` constructors so `request.grant_type` returns
|
|
29
69
|
the correct value in hooks like `before_successful_strategy_response`.
|
|
70
|
+
- [#1801] Fix `hash_application_secrets` fallback not upgrading secret on access.
|
|
30
71
|
- [#1802] Fix `filter_parameters` not applied when `Doorkeeper.configure` is called inside to_prepare.
|
|
31
72
|
- [#1804] Use `ActiveSupport.on_load(:active_record)` in ORM hooks to prevent loading ActiveRecord models too early
|
|
32
73
|
- [#1806] Fix token revocation bypass for public clients (RFC 7009)
|
data/README.md
CHANGED
|
@@ -24,6 +24,7 @@ Supported features:
|
|
|
24
24
|
- [OAuth 2.0 Threat Model and Security Considerations](https://datatracker.ietf.org/doc/html/rfc6819)
|
|
25
25
|
- [OAuth 2.0 for Native Apps](https://datatracker.ietf.org/doc/html/rfc8252)
|
|
26
26
|
- [Proof Key for Code Exchange by OAuth Public Clients](https://datatracker.ietf.org/doc/html/rfc7636)
|
|
27
|
+
- [OAuth 2.0 Authorization Server Issuer Identification](https://datatracker.ietf.org/doc/html/rfc9207) — opt-in by setting `issuer`; adds the `iss` parameter to authorization redirects returned to the client
|
|
27
28
|
|
|
28
29
|
## Table of Contents
|
|
29
30
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Doorkeeper
|
|
4
|
+
class MetadataController < Doorkeeper::ApplicationMetalController
|
|
5
|
+
def show
|
|
6
|
+
headers.merge!(metadata_response.headers)
|
|
7
|
+
render json: metadata_response.body,
|
|
8
|
+
status: metadata_response.status
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def metadata_response
|
|
14
|
+
@metadata_response ||= Doorkeeper::OAuth::MetadataResponse.new(
|
|
15
|
+
request.base_url,
|
|
16
|
+
->(**args) { url_for(**args) },
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -34,7 +34,7 @@ module Doorkeeper
|
|
|
34
34
|
|
|
35
35
|
# OAuth 2.0 Token Introspection - https://datatracker.ietf.org/doc/html/rfc7662
|
|
36
36
|
def introspect
|
|
37
|
-
introspection = OAuth::TokenIntrospection.new(server, token)
|
|
37
|
+
introspection = OAuth::TokenIntrospection.new(server, token, token_type: presented_token_type)
|
|
38
38
|
|
|
39
39
|
if introspection.authorized?
|
|
40
40
|
render json: introspection.to_json, status: 200
|
|
@@ -138,6 +138,15 @@ module Doorkeeper
|
|
|
138
138
|
RevocableTokens::RevocableRefreshToken.new(token)
|
|
139
139
|
end
|
|
140
140
|
|
|
141
|
+
# Revocation (RFC 7009) and introspection (RFC 7662) deliberately share
|
|
142
|
+
# the same request shape — `token` plus an optional `token_type_hint` —
|
|
143
|
+
# so both actions resolve the presented token through #revocable_token.
|
|
144
|
+
# The wrapper type doubles as the record of which credential the client
|
|
145
|
+
# actually presented.
|
|
146
|
+
def presented_token_type
|
|
147
|
+
revocable_token.is_a?(RevocableTokens::RevocableRefreshToken) ? :refresh_token : :access_token
|
|
148
|
+
end
|
|
149
|
+
|
|
141
150
|
def access_token
|
|
142
151
|
token = Doorkeeper.config.access_token_model.by_token(params["token"])
|
|
143
152
|
return unless token
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
<%= hidden_field_tag :scope, @pre_auth.scope, id: nil %>
|
|
30
30
|
<%= hidden_field_tag :code_challenge, @pre_auth.code_challenge, id: nil %>
|
|
31
31
|
<%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method, id: nil %>
|
|
32
|
+
<% @pre_auth.custom_access_token_attributes.each do |attribute_name, attribute_value| %>
|
|
33
|
+
<%= hidden_field_tag attribute_name, attribute_value, id: nil %>
|
|
34
|
+
<% end %>
|
|
32
35
|
<%= submit_tag t('doorkeeper.authorizations.buttons.authorize'), class: "btn btn-success btn-lg btn-block" %>
|
|
33
36
|
<% end %>
|
|
34
37
|
<%= form_tag oauth_authorization_path, method: :delete do %>
|
|
@@ -40,6 +43,9 @@
|
|
|
40
43
|
<%= hidden_field_tag :scope, @pre_auth.scope, id: nil %>
|
|
41
44
|
<%= hidden_field_tag :code_challenge, @pre_auth.code_challenge, id: nil %>
|
|
42
45
|
<%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method, id: nil %>
|
|
46
|
+
<% @pre_auth.custom_access_token_attributes.each do |attribute_name, attribute_value| %>
|
|
47
|
+
<%= hidden_field_tag attribute_name, attribute_value, id: nil %>
|
|
48
|
+
<% end %>
|
|
43
49
|
<%= submit_tag t('doorkeeper.authorizations.buttons.deny'), class: "btn btn-danger btn-lg btn-block" %>
|
|
44
50
|
<% end %>
|
|
45
51
|
</div>
|
data/config/locales/en.yml
CHANGED
|
@@ -97,6 +97,7 @@ en:
|
|
|
97
97
|
missing_param: 'Missing required parameter: %{value}.'
|
|
98
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
|
+
multiple_client_auth_methods: 'The request utilizes more than one mechanism for authenticating the client.'
|
|
100
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.'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Doorkeeper
|
|
4
|
+
module ClientAuthentication
|
|
5
|
+
Credentials = Struct.new(:uid, :secret) do
|
|
6
|
+
# Public clients may have their secret blank, but "credentials" are
|
|
7
|
+
# still present as long as the uid is present.
|
|
8
|
+
delegate :blank?, to: :uid
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Doorkeeper
|
|
4
|
+
module ClientAuthentication
|
|
5
|
+
# Used when no registered client authentication method matches the
|
|
6
|
+
# request. It matches everything and authenticates to nothing, mirroring
|
|
7
|
+
# the previous behaviour where an unauthenticated request simply yielded
|
|
8
|
+
# no credentials.
|
|
9
|
+
class FallbackMethod
|
|
10
|
+
def self.matches_request?(_request)
|
|
11
|
+
true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.authenticate(_request)
|
|
15
|
+
nil
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Doorkeeper
|
|
4
|
+
module ClientAuthentication
|
|
5
|
+
# Adapter that lets a legacy callable +client_credentials+ extractor
|
|
6
|
+
# (e.g. +->(request) { [client_id, client_secret] }+) keep working through
|
|
7
|
+
# the client authentication registry during the deprecation window.
|
|
8
|
+
#
|
|
9
|
+
# The callable is expected to return a +[uid, secret]+ pair (or +nil+ when
|
|
10
|
+
# it does not apply), matching the historical +Credentials.from_request+
|
|
11
|
+
# contract. It is considered to match a request whenever it yields present
|
|
12
|
+
# credentials, mirroring the previous "first extractor that returns a uid
|
|
13
|
+
# wins" behaviour.
|
|
14
|
+
class LegacyCallable
|
|
15
|
+
def initialize(callable)
|
|
16
|
+
@callable = callable
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def matches_request?(request)
|
|
20
|
+
credentials_for(request).present?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def authenticate(request)
|
|
24
|
+
credentials_for(request)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# Invoke the wrapped extractor at most once per request. +matches_request?+
|
|
30
|
+
# and +authenticate+ both need the extracted credentials, and the legacy
|
|
31
|
+
# +Credentials.from_request+ contract called each extractor exactly once,
|
|
32
|
+
# so cache the result on the request itself to preserve that. The adapter
|
|
33
|
+
# is stored in the config/registry and therefore shared across requests
|
|
34
|
+
# and threads, so the cache must live on the per-request +env+ (keyed per
|
|
35
|
+
# adapter instance) rather than on the adapter, which would otherwise race.
|
|
36
|
+
def credentials_for(request)
|
|
37
|
+
request.env[cache_key] ||=
|
|
38
|
+
Doorkeeper::ClientAuthentication::Credentials.new(*@callable.call(request))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def cache_key
|
|
42
|
+
@cache_key ||= "doorkeeper.client_authentication.legacy_callable.#{@callable.object_id}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Doorkeeper
|
|
4
|
+
module ClientAuthentication
|
|
5
|
+
# Wraps a registered client authentication method, pairing its
|
|
6
|
+
# registration +name+ with the +strategy+ object that knows how to match
|
|
7
|
+
# and authenticate a request.
|
|
8
|
+
#
|
|
9
|
+
# NOTE: the wrapped object is exposed as +strategy+ rather than +method+ on
|
|
10
|
+
# purpose — an +attr_reader :method+ would shadow Ruby's core
|
|
11
|
+
# +Object#method+ reflection API and break +wrapper.method(:authenticate)+.
|
|
12
|
+
class Method
|
|
13
|
+
attr_reader :name, :strategy
|
|
14
|
+
|
|
15
|
+
delegate :matches_request?, :authenticate, to: :strategy
|
|
16
|
+
|
|
17
|
+
def initialize(name, strategy)
|
|
18
|
+
@name = name
|
|
19
|
+
@strategy = strategy
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Doorkeeper
|
|
4
|
+
module ClientAuthentication
|
|
5
|
+
# Holds the registered client authentication methods and provides the DSL
|
|
6
|
+
# to register and look them up by name.
|
|
7
|
+
module Registry
|
|
8
|
+
mattr_accessor :registered_methods
|
|
9
|
+
self.registered_methods = {}
|
|
10
|
+
|
|
11
|
+
# Allows to register a custom OAuth client authentication method so that
|
|
12
|
+
# Doorkeeper could recognize and process it.
|
|
13
|
+
#
|
|
14
|
+
def register(name, method)
|
|
15
|
+
unless name.respond_to?(:to_sym)
|
|
16
|
+
raise ArgumentError,
|
|
17
|
+
"client authentication method name must be a Symbol or String, got #{name.inspect}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
unless method.respond_to?(:matches_request?) && method.respond_to?(:authenticate)
|
|
21
|
+
raise ArgumentError,
|
|
22
|
+
"client authentication method '#{name}' must respond to " \
|
|
23
|
+
"#matches_request? and #authenticate, got #{method.inspect}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
name_key = name.to_sym
|
|
27
|
+
|
|
28
|
+
if registered_methods.key?(name_key)
|
|
29
|
+
::Kernel.warn <<~WARNING
|
|
30
|
+
[DOORKEEPER] '#{name_key}' client authentication strategy is already registered and will be overridden
|
|
31
|
+
in #{caller(1..1).first}
|
|
32
|
+
WARNING
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
registered_methods[name_key] = Doorkeeper::ClientAuthentication::Method.new(name_key, method)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# [NOTE]: switch to #fetch once the deprecated client_credentials
|
|
39
|
+
# fallbacks are removed.
|
|
40
|
+
def get(name)
|
|
41
|
+
return unless name.respond_to?(:to_sym)
|
|
42
|
+
|
|
43
|
+
registered_methods[name.to_sym]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "doorkeeper/client_authentication/credentials"
|
|
4
|
+
require "doorkeeper/client_authentication/fallback_method"
|
|
5
|
+
require "doorkeeper/client_authentication/legacy_callable"
|
|
6
|
+
require "doorkeeper/client_authentication/method"
|
|
7
|
+
require "doorkeeper/client_authentication/registry"
|
|
8
|
+
|
|
9
|
+
module Doorkeeper
|
|
10
|
+
# Registry of the OAuth client authentication methods (RFC 6749 §2.3)
|
|
11
|
+
# Doorkeeper knows how to process. Each registered method is able to tell
|
|
12
|
+
# whether it +matches_request?+ and how to +authenticate+ it into a
|
|
13
|
+
# Credentials object.
|
|
14
|
+
module ClientAuthentication
|
|
15
|
+
extend Registry
|
|
16
|
+
|
|
17
|
+
# Default ordered client authentication methods (RFC 6749 §2.3) used when
|
|
18
|
+
# +client_authentication+ is not configured.
|
|
19
|
+
DEFAULT_METHODS = %i[client_secret_basic client_secret_post none].freeze
|
|
20
|
+
|
|
21
|
+
# Maps the current method names back onto the deprecated +client_credentials+
|
|
22
|
+
# names so the +client_credentials_methods+ alias can keep returning the
|
|
23
|
+
# legacy symbols that external callers (e.g. doorkeeper-openid_connect) map
|
|
24
|
+
# from. Names without a legacy equivalent (e.g. +:none+, custom methods) are
|
|
25
|
+
# returned unchanged — consumers that don't recognise them drop them, just
|
|
26
|
+
# as they did before.
|
|
27
|
+
LEGACY_NAME_FOR = {
|
|
28
|
+
client_secret_basic: :from_basic,
|
|
29
|
+
client_secret_post: :from_params,
|
|
30
|
+
}.freeze
|
|
31
|
+
|
|
32
|
+
# Converts resolved Method objects into the legacy client_credentials
|
|
33
|
+
# symbol names for the deprecated +client_credentials_methods+ alias.
|
|
34
|
+
def self.to_legacy_client_credentials_names(methods)
|
|
35
|
+
methods.map { |method| LEGACY_NAME_FOR.fetch(method.name, method.name) }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
register(
|
|
39
|
+
:none,
|
|
40
|
+
Doorkeeper::OAuth::ClientAuthentication::None,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
register(
|
|
44
|
+
:client_secret_post,
|
|
45
|
+
Doorkeeper::OAuth::ClientAuthentication::ClientSecretPost,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
register(
|
|
49
|
+
:client_secret_basic,
|
|
50
|
+
Doorkeeper::OAuth::ClientAuthentication::ClientSecretBasic,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Converts a deprecated +client_credentials+ configuration into the client
|
|
54
|
+
# authentication method names / adapters understood by the registry.
|
|
55
|
+
# Unknown values are warned about and dropped; callables are wrapped in a
|
|
56
|
+
# LegacyCallable adapter. +:none+ (public client support) is appended only
|
|
57
|
+
# for +:from_params+ — the sole legacy method that accepted a bare
|
|
58
|
+
# +client_id+ without a secret — so a Basic-only configuration is not
|
|
59
|
+
# silently broadened.
|
|
60
|
+
def self.from_legacy_client_credentials(methods)
|
|
61
|
+
converted = methods.filter_map { |method| legacy_client_credential(method) }
|
|
62
|
+
converted.push(:none) if methods.include?(:from_params)
|
|
63
|
+
converted
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def self.legacy_client_credential(method)
|
|
67
|
+
case method
|
|
68
|
+
when :from_basic
|
|
69
|
+
:client_secret_basic
|
|
70
|
+
when :from_params
|
|
71
|
+
:client_secret_post
|
|
72
|
+
else
|
|
73
|
+
legacy_extractor_or_nil(method)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
private_class_method :legacy_client_credential
|
|
77
|
+
|
|
78
|
+
def self.legacy_extractor_or_nil(method)
|
|
79
|
+
unless method.respond_to?(:call)
|
|
80
|
+
Kernel.warn("[DOORKEEPER] Unknown client_credentials method detected: #{method}")
|
|
81
|
+
return nil
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
Kernel.warn(
|
|
85
|
+
"[DOORKEEPER] client_credentials callable extractors are deprecated; wrapping it in a " \
|
|
86
|
+
"legacy client authentication adapter. Register it via " \
|
|
87
|
+
"Doorkeeper::ClientAuthentication.register instead.",
|
|
88
|
+
)
|
|
89
|
+
Method.new(:legacy_callable, LegacyCallable.new(method))
|
|
90
|
+
end
|
|
91
|
+
private_class_method :legacy_extractor_or_nil
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -74,7 +74,7 @@ module Doorkeeper
|
|
|
74
74
|
def self.extended(base)
|
|
75
75
|
return if base.respond_to?(:builder_class)
|
|
76
76
|
|
|
77
|
-
raise Doorkeeper::MissingConfigurationBuilderClass, "Define `self.builder_class` method " \
|
|
77
|
+
raise Doorkeeper::Errors::MissingConfigurationBuilderClass, "Define `self.builder_class` method " \
|
|
78
78
|
"for #{base} that returns your custom Builder class to use options DSL!"
|
|
79
79
|
end
|
|
80
80
|
end
|
|
@@ -8,14 +8,68 @@ module Doorkeeper
|
|
|
8
8
|
# Validates configuration options to be set properly.
|
|
9
9
|
#
|
|
10
10
|
def validate!
|
|
11
|
+
validate_client_authentication_conflict
|
|
12
|
+
validate_client_authentication_registered
|
|
11
13
|
validate_reuse_access_token_value
|
|
12
14
|
validate_token_reuse_limit
|
|
13
15
|
validate_secret_strategies
|
|
14
16
|
validate_pkce_code_challenge_methods
|
|
17
|
+
validate_custom_metadata
|
|
18
|
+
validate_refresh_token_flow
|
|
19
|
+
validate_issuer_format
|
|
20
|
+
validate_issuer_metadata_discoverability
|
|
15
21
|
end
|
|
16
22
|
|
|
17
23
|
private
|
|
18
24
|
|
|
25
|
+
# Warn once, at configuration time, when both the deprecated
|
|
26
|
+
# +client_credentials+ and the new +client_authentication+ options are
|
|
27
|
+
# set. +client_authentication+ takes precedence; the warning lives here
|
|
28
|
+
# (rather than in the memoised resolver) so it is not swallowed and
|
|
29
|
+
# surfaces during boot instead of on the first request.
|
|
30
|
+
def validate_client_authentication_conflict
|
|
31
|
+
return unless instance_variable_defined?(:@client_credentials_methods) &&
|
|
32
|
+
instance_variable_defined?(:@client_authentication)
|
|
33
|
+
|
|
34
|
+
::Rails.logger.warn(
|
|
35
|
+
"[DOORKEEPER] Both client_credentials and client_authentication are set, " \
|
|
36
|
+
"using client_authentication",
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Warn about configured client authentication methods that are not
|
|
41
|
+
# registered (e.g. a typo, or an extension that failed to load). Such
|
|
42
|
+
# names are silently ignored when resolving the methods, which could
|
|
43
|
+
# otherwise leave the application with no usable authentication methods.
|
|
44
|
+
def validate_client_authentication_registered
|
|
45
|
+
# The deprecated client_credentials path already validates its own input.
|
|
46
|
+
return if instance_variable_defined?(:@client_credentials_methods) &&
|
|
47
|
+
!instance_variable_defined?(:@client_authentication)
|
|
48
|
+
|
|
49
|
+
configured = client_authentication
|
|
50
|
+
unknown = configured.reject { |name| Doorkeeper::ClientAuthentication.get(name) }
|
|
51
|
+
|
|
52
|
+
unless unknown.empty?
|
|
53
|
+
::Rails.logger.warn(
|
|
54
|
+
"[DOORKEEPER] Unknown client authentication method(s) configured and will be ignored: " \
|
|
55
|
+
"#{unknown.map(&:inspect).join(", ")}. " \
|
|
56
|
+
"Ensure each method is registered (e.g. by the extension that provides it).",
|
|
57
|
+
)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# A configuration that resolves to zero usable methods fails every
|
|
61
|
+
# client authentication attempt (all requests fall back to no
|
|
62
|
+
# credentials), so make that loud rather than silent.
|
|
63
|
+
return unless (configured - unknown).empty?
|
|
64
|
+
|
|
65
|
+
::Rails.logger.error(
|
|
66
|
+
"[DOORKEEPER] No usable client authentication methods are configured " \
|
|
67
|
+
"(client_authentication resolved to an empty set). All client authentication " \
|
|
68
|
+
"will fail. Configure at least one registered method, e.g. " \
|
|
69
|
+
"client_authentication #{Doorkeeper::ClientAuthentication::DEFAULT_METHODS.inspect}.",
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
19
73
|
# Determine whether +reuse_access_token+ and a non-restorable
|
|
20
74
|
# +token_secret_strategy+ have both been activated.
|
|
21
75
|
#
|
|
@@ -51,7 +105,15 @@ module Doorkeeper
|
|
|
51
105
|
end
|
|
52
106
|
|
|
53
107
|
def validate_pkce_code_challenge_methods
|
|
54
|
-
|
|
108
|
+
methods = pkce_code_challenge_methods.map(&:to_s)
|
|
109
|
+
if methods.all? { |method| method.match?(/\A(?:plain|S256)\z/) }
|
|
110
|
+
# Persist the normalized (string) values only when the option was
|
|
111
|
+
# explicitly configured — the default is already normalized, and an
|
|
112
|
+
# unconfigured option should stay undefined rather than have
|
|
113
|
+
# validation flip its instance_variable_defined? signal.
|
|
114
|
+
@pkce_code_challenge_methods = methods if instance_variable_defined?(:@pkce_code_challenge_methods)
|
|
115
|
+
return
|
|
116
|
+
end
|
|
55
117
|
|
|
56
118
|
::Rails.logger.warn(
|
|
57
119
|
"[DOORKEEPER] You have configured an invalid value for pkce_code_challenge_methods option. " \
|
|
@@ -60,6 +122,105 @@ module Doorkeeper
|
|
|
60
122
|
|
|
61
123
|
@pkce_code_challenge_methods = ["plain", "S256"]
|
|
62
124
|
end
|
|
125
|
+
|
|
126
|
+
def validate_custom_metadata
|
|
127
|
+
return if custom_metadata.is_a? Hash
|
|
128
|
+
|
|
129
|
+
::Rails.logger.warn(
|
|
130
|
+
"[DOORKEEPER] You have configured an invalid value for custom_metadata option. " \
|
|
131
|
+
"It must be a Hash, and will be overridden with an empty hash.",
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
@custom_metadata = {}
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Warn when the refresh_token grant flow is enabled but refresh tokens
|
|
138
|
+
# are never issued: refresh token requests would always fail because
|
|
139
|
+
# there are no tokens to refresh. The flow is enabled automatically
|
|
140
|
+
# when +use_refresh_token+ is configured, so it doesn't need to be
|
|
141
|
+
# listed in +grant_flows+ explicitly.
|
|
142
|
+
#
|
|
143
|
+
# +calculate_grant_flows+ is used (rather than the raw +grant_flows+) so
|
|
144
|
+
# that the flow is also detected when enabled through a registered
|
|
145
|
+
# grant-flow alias. When +use_refresh_token+ is not configured the
|
|
146
|
+
# refresh_token flow is not appended implicitly, so its presence there
|
|
147
|
+
# means it was requested explicitly (directly or via an alias).
|
|
148
|
+
def validate_refresh_token_flow
|
|
149
|
+
return if refresh_token_enabled?
|
|
150
|
+
return unless calculate_grant_flows.map(&:to_s).include?("refresh_token")
|
|
151
|
+
|
|
152
|
+
::Rails.logger.warn(
|
|
153
|
+
"[DOORKEEPER] You have enabled the refresh_token grant flow without " \
|
|
154
|
+
"configuring use_refresh_token, so refresh tokens will not be issued. " \
|
|
155
|
+
"Configure use_refresh_token to issue refresh tokens (the refresh_token " \
|
|
156
|
+
"grant flow is then enabled automatically).",
|
|
157
|
+
)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Warn when a configured issuer is not RFC-compliant. RFC 8414 (the
|
|
161
|
+
# metadata issuer) and RFC 9207 (the authorization response iss parameter)
|
|
162
|
+
# both require an https URL with a host and no query or fragment component.
|
|
163
|
+
# The value is still used as-is - this is a warning, not a hard failure, so
|
|
164
|
+
# local setups using e.g. http://localhost keep working - but a
|
|
165
|
+
# non-compliant issuer produces responses that strict clients may reject.
|
|
166
|
+
def validate_issuer_format
|
|
167
|
+
return if issuer.blank?
|
|
168
|
+
|
|
169
|
+
uri =
|
|
170
|
+
begin
|
|
171
|
+
URI.parse(issuer.to_s)
|
|
172
|
+
rescue URI::InvalidURIError
|
|
173
|
+
nil
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
return if uri.is_a?(URI::HTTPS) && uri.host.present? &&
|
|
177
|
+
uri.query.nil? && uri.fragment.nil?
|
|
178
|
+
|
|
179
|
+
::Rails.logger.warn(
|
|
180
|
+
"[DOORKEEPER] issuer #{redacted_issuer.inspect} is not RFC-compliant: " \
|
|
181
|
+
"RFC 8414 and RFC 9207 require an https URL with a host and no query " \
|
|
182
|
+
"or fragment component. It is still advertised in the metadata and " \
|
|
183
|
+
"emitted as the iss parameter as-is, but strict clients may reject it.",
|
|
184
|
+
)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Warn when a path-bearing issuer cannot be discovered. RFC 8414 clients
|
|
188
|
+
# build the metadata URL by inserting the well-known path into the issuer,
|
|
189
|
+
# so an issuer of https://host/tenant is looked up at
|
|
190
|
+
# https://host/.well-known/oauth-authorization-server/tenant. Doorkeeper
|
|
191
|
+
# only serves the document at the root well-known path, so such a value is
|
|
192
|
+
# not discoverable (and its advertised issuer would not match the lookup).
|
|
193
|
+
# This is a separate concern from validate_issuer_format: a path component
|
|
194
|
+
# is valid per RFC 8414, just unsupported by Doorkeeper's fixed route.
|
|
195
|
+
def validate_issuer_metadata_discoverability
|
|
196
|
+
return if issuer.blank?
|
|
197
|
+
|
|
198
|
+
uri =
|
|
199
|
+
begin
|
|
200
|
+
URI.parse(issuer.to_s)
|
|
201
|
+
rescue URI::InvalidURIError
|
|
202
|
+
nil
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
return if uri&.host.blank?
|
|
206
|
+
return if uri.path.blank? || uri.path == "/"
|
|
207
|
+
|
|
208
|
+
::Rails.logger.warn(
|
|
209
|
+
"[DOORKEEPER] issuer #{redacted_issuer.inspect} has a path component, but " \
|
|
210
|
+
"Doorkeeper serves its RFC 8414 metadata only at the root " \
|
|
211
|
+
"/.well-known/oauth-authorization-server. RFC 8414 clients derive the " \
|
|
212
|
+
"metadata URL from the issuer path (…/.well-known/" \
|
|
213
|
+
"oauth-authorization-server#{uri.path}), so they will not discover the " \
|
|
214
|
+
"document. Use a host-only issuer, or route the derived well-known path " \
|
|
215
|
+
"to Doorkeeper.",
|
|
216
|
+
)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# Redact any userinfo (e.g. a misconfigured user:pass@host) before the
|
|
220
|
+
# issuer is written to the log, so credentials are not leaked there.
|
|
221
|
+
def redacted_issuer
|
|
222
|
+
issuer.to_s.sub(%r{//[^/@]*@}, "//***@")
|
|
223
|
+
end
|
|
63
224
|
end
|
|
64
225
|
end
|
|
65
226
|
end
|