doorkeeper-openid_connect 1.10.1 → 1.10.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6e40af64a066cdb6b80a91eb5ecb97016c6c4a0695c4a362f72942577b7a1bd
4
- data.tar.gz: 57999fcd4eba595ca726f41767c301dbd652b76ea039787d9f00fa5177b7aefa
3
+ metadata.gz: 4bedc8346eca194f64043d9326c448e386f3cf3ba3a9f1e3be620bef94f809f2
4
+ data.tar.gz: 04a5b33f8edb2ddd2ae4dc792ce40649aa1e65548953565cdf0edc9332e5013b
5
5
  SHA512:
6
- metadata.gz: 7a722b6a8cf208f7c9ba6af64c8b4518a20d206d991f81f45d0a5fa21fffead56f6c134c0bb65f1de9e8d0addba5b3db408df02ed10d9a70f55b4d343ee3fb6c
7
- data.tar.gz: afd99576ba3f10b38b55cd9cb2ed721ebed97a33aba778939c6aabae07ca91a07a2f4531a178716dda14adb2b4641a627c2bf9d38a8fe8b89d65a1e971ecd5c4
6
+ metadata.gz: c125fedebc47c300e44a8c62e0424e180cdb48173a4cea5faab0928e9698738495f5cd9ddb7a55d482919dd84dbf02a059e268fb239d60c95648a935fb0b8b6e
7
+ data.tar.gz: fbedda34c90a57041aab6683f88ab5c57135894f86f6dc0c5872f062cdb881a029323ae05c59e63d4286108ed492122a3269c67fd8244a214a43f6713545a0ca
data/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  - Please add here
4
4
 
5
+ ## v1.10.3 (2026-06-23)
6
+
7
+ - [#308] Fix `NameError: uninitialized constant Auth::ApplicationRecord` on boot when using a namespaced custom access grant model (e.g. `Auth::OAuthAccessGrant < ApplicationRecord`). Since v1.10.0 ([#241]) the `openid_request` association was wired inside an `ActiveSupport.on_load(:active_record)` block, which fires while `ActiveRecord::Base` is first loaded and constantizes the grant model too early. The association is now added from Doorkeeper's `AccessGrant` mixin `included` callback — at the model's own load time, without constantizing — mirroring the fix doorkeeper made in [#1830](https://github.com/doorkeeper-gem/doorkeeper/pull/1830) ([#306](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/issues/306))
8
+
9
+ ## v1.10.2 (2026-06-22)
10
+
11
+ - [#315] Drop support for EOL Ruby 3.1 (EOL 2025-03-25) and require Ruby `>= 3.2`. `i18n 1.15.0` uses the `Fiber[]` storage API which only exists on Ruby 3.2+, so the Ruby 3.1 CI row no longer loads; the matrix now tests Ruby 3.2 as the minimum
12
+ - [#316] Set `fail-fast: false` in CI matrix so a single failing job no longer cancels the rest
13
+ - [#303] execute account selection even without owner, and `select_account_for_resource_owner` can now receive `nil` as the first argument.
14
+ - [#304] allow handle auth_time per grant
15
+ - [#305] Document the `auth_time_from_access_token` config option in the README (per-grant `auth_time`), clarifying that it only affects the ID Token `auth_time` claim and not `max_age` enforcement
16
+ - [#307] Fix `bundle exec rake server` for the test application
17
+ - [#313] Move Configuration documentation from README to Wiki
18
+ - [#312] Raise `Errors::MissingRequiredClaim` instead of silently dropping a blank REQUIRED ID Token claim (`iss`/`sub`/`aud`/`exp`/`iat`) in `IdToken#as_json`, which previously could emit a non-conformant ID Token (OIDC Core 1.0 §2). OPTIONAL claims such as `nonce`/`auth_time` are still omitted when blank
19
+ - [#311] Include the REQUIRED `client_secret_expires_at` member (value `0`, never expires) in the Dynamic Client Registration response whenever a `client_secret` is issued (RFC 7591 §3.2.1 / OpenID Connect Dynamic Client Registration 1.0 §3.2)
20
+ - [#309] Add a browser dashboard to the test application (`spec/dummy`) for exercising the OpenID Connect endpoints by hand — replacing the rails console + curl workflow with forms for Setup, Discovery, Authorization (code / implicit / PKCE / nonce / prompt / `max_age`), token exchange, UserInfo, introspection and revocation
21
+
5
22
  ## v1.10.1 (2026-06-03)
6
23
 
7
24
  - [#294] Drop stale `Metrics/ClassLength` and `Metrics/BlockLength` overrides from `.rubocop_todo.yml`
data/README.md CHANGED
@@ -14,13 +14,7 @@ OpenID Connect is a single-sign-on and identity layer with a [growing list of se
14
14
  - [Known Issues](#known-issues)
15
15
  - [Example Applications](#example-applications)
16
16
  - [Installation](#installation)
17
- - [Configuration](#configuration)
18
- - [Scopes](#scopes)
19
- - [Claims](#claims)
20
- - [Routes](#routes)
21
- - [Nonces](#nonces)
22
- - [Internationalization (I18n)](#internationalization-i18n)
23
- - [Dynamic Client Registration](#dynamic-client-registration)
17
+ - [Configuration](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/wiki/Configuration)
24
18
  - [Development](#development)
25
19
  - [License](#license)
26
20
  - [Sponsors](#sponsors)
@@ -77,526 +71,14 @@ wiki and [CHANGELOG.md](CHANGELOG.md) for upgrade instructions.
77
71
 
78
72
  ## Configuration
79
73
 
80
- Make sure you've [configured Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper#configuration) before continuing.
81
-
82
- Verify your settings in `config/initializers/doorkeeper.rb`:
83
-
84
- - `resource_owner_authenticator`
85
- - This callback needs to returns a falsey value if the current user can't be determined:
86
-
87
- ```ruby
88
- resource_owner_authenticator do
89
- if current_user
90
- current_user
91
- else
92
- redirect_to(new_user_session_url)
93
- nil
94
- end
95
- end
96
- ```
97
- - `grant_flows`
98
- - If you want to use `id_token` or `id_token token` response types you need to add `implicit_oidc` to `grant_flows`:
99
-
100
- ```ruby
101
- grant_flows %w(authorization_code implicit_oidc)
102
- ```
103
-
104
- The following settings are required in `config/initializers/doorkeeper_openid_connect.rb`:
105
-
106
- - `issuer`
107
- - Identifier for the issuer of the response (i.e. your application URL). The value is a case sensitive URL using the `https` scheme that contains scheme, host, and optionally, port number and path components and no query or fragment components.
108
- - You can either pass a string value, or a block to generate the issuer dynamically. The block receives `resource_owner`, `application`, and `request` so that the same configuration can serve both ID token issuance (where `resource_owner` and `application` are available) and the discovery endpoint (where only `request` is available):
109
-
110
- ```ruby
111
- # config/initializers/doorkeeper_openid_connect.rb
112
- Doorkeeper::OpenidConnect.configure do
113
- # ...
114
- issuer do |resource_owner, application, request|
115
- request&.base_url || "https://default.example.com"
116
- end
117
- end
118
- ```
119
-
120
- - For backward compatibility, blocks with arity 0, 1, or 2 are also accepted. An arity-1 block receives `request` from the discovery endpoint and `resource_owner` from the ID token context, while an arity-2 block always receives `resource_owner` and `application`.
121
- - `subject`
122
- - Identifier for the resource owner (i.e. the authenticated user). A locally unique and never reassigned identifier within the issuer for the end-user, which is intended to be consumed by the client. The value is a case-sensitive string and must not exceed 255 ASCII characters in length.
123
- - The database ID of the user is an acceptable choice if you don't mind leaking that information.
124
- - If you want to provide a different subject identifier to each client, use [pairwise subject identifier](http://openid.net/specs/openid-connect-core-1_0.html#SubjectIDTypes) with configurations like below.
125
-
126
- ```ruby
127
- # config/initializers/doorkeeper_openid_connect.rb
128
- Doorkeeper::OpenidConnect.configure do
129
- # ...
130
- subject_types_supported [:pairwise]
131
-
132
- subject do |resource_owner, application|
133
- Digest::SHA256.hexdigest("#{resource_owner.id}#{URI.parse(application.redirect_uri).host}#{'your_secret_salt'}")
134
- end
135
- # ...
136
- end
137
- ```
138
-
139
- - `signing_key`
140
- - Private key to be used for [JSON Web Signature](https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-31).
141
- - You can generate a private key with the `openssl` command, see e.g. [Generate an RSA keypair using OpenSSL](https://en.wikibooks.org/wiki/Cryptography/Generate_a_keypair_using_OpenSSL).
142
- - You should not commit the key to your repository, but use an external file (in combination with `File.read`) and/or the [dotenv-rails](https://github.com/bkeepers/dotenv) gem (in combination with `ENV[...]`).
143
- - `signing_algorithm`
144
- - The signing algorithm used for the ID token, which defaults to `:rs256`. The list of supported algorithms can be found [here](https://github.com/jwt/ruby-jwt#algorithms-and-usage)
145
- - `resource_owner_from_access_token`
146
- - Defines how to translate the Doorkeeper access token to a resource owner model.
147
-
148
- > [!Note]
149
- > Both `signing_key` and `signing_algorithm` also accept callable objects (e.g. a lambda), which are evaluated on each call — useful for multi-tenant setups where the key or algorithm varies per request:
150
- >
151
- > ```ruby
152
- > signing_key -> { current_tenant.private_key }
153
- > signing_algorithm -> { current_tenant.algorithm }
154
- > ```
155
-
156
- > [!Note]
157
- > `signing_key` also accepts an array for key rotation. The first entry is the active key used to sign newly issued ID tokens; the remaining entries are still published in the JWKS so clients can validate tokens signed with a retired key during a rotation window. Callable forms returning an array are also supported.
158
- >
159
- > ```ruby
160
- > signing_key [
161
- > File.read("config/keys/current.pem"), # active, signs new tokens
162
- > File.read("config/keys/previous.pem"), # retired, exposed in JWKS only
163
- > ]
164
- > ```
165
-
166
- The following settings are optional, but recommended for better client compatibility:
167
-
168
- - `auth_time_from_resource_owner`
169
- - Returns the time of the user's last login, this can be a `Time`, `DateTime`, or any other class that responds to `to_i`
170
- - Used to populate the `auth_time` claim on the ID Token.
171
- - Used as a fallback for `max_age` enforcement when `auth_time_from_session` is not configured. **Note:** for multi-session deployments this is insecure (it returns the most recent login on _any_ device), and emits a deprecation warning — prefer `auth_time_from_session` below.
172
- - `auth_time_from_session`
173
- - Returns the time the user authenticated for the *current* session. Required for correct `max_age` enforcement when the same user can hold multiple concurrent sessions (e.g. PC + smartphone) — `auth_time_from_resource_owner` cannot distinguish between sessions and would let a stale session inherit a fresh login from another device.
174
- - The block is executed in the controller's scope and receives `(session, request)`. Return value can be a `Time`, `DateTime`, or anything responding to `to_i`. Return `nil` to force reauthentication.
175
-
176
- ```ruby
177
- # Example: capture auth_time on the session at login,
178
- # and surface it here for the OIDC max_age check.
179
- auth_time_from_session do |session, _request|
180
- session[:auth_time]
181
- end
182
- ```
183
- - `reauthenticate_resource_owner`
184
- - Defines how to trigger reauthentication for the current user (e.g. display a password prompt, or sign-out the user and redirect to the login form).
185
- - Required to support the `max_age` and `prompt=login` parameters.
186
- - The block is executed in the controller's scope, so you have access to methods like `params`, `redirect_to` etc.
187
- - `select_account_for_resource_owner`
188
- - Defines how to trigger account selection to choose the current login user.
189
- - Required to support the `prompt=select_account` parameter.
190
- - The block is executed in the controller's scope, so you have access to methods like `params`, `redirect_to` etc.
191
-
192
- The following settings are optional:
193
-
194
- - `expiration`
195
- - Expiration time after which the ID Token must not be accepted for processing by clients.
196
- - The default is 120 seconds, it can be configured using a value or block.
197
- ```ruby
198
- # config/initializers/doorkeeper_openid_connect.rb
199
- Doorkeeper::OpenidConnect.configure do
200
- # ...
201
- expiration do |resource_owner, application|
202
- # You will have to ensure the application model implements an expiration method
203
- application.expiration
204
- end
205
- # ...
206
- end
207
- ```
208
-
209
- - `protocol`
210
- - The protocol to use when generating URIs for the discovery endpoints.
211
- - The default is `https` for production, and `http` for all other environments
212
- - Note that the OIDC specification mandates HTTPS, so you shouldn't change this
213
- for production environments unless you have a really good reason!
214
-
215
- - `end_session_endpoint`
216
- - The URL that the user is redirected to after ending the session on the client.
217
- - Used by implementations like https://github.com/IdentityModel/oidc-client-js.
218
- - The block is executed in the controller's scope, so you have access to your route helpers.
219
-
220
- - `discovery_url_options`
221
- - The URL options for every available endpoint to use when generating the endpoint URL in the
222
- discovery response. Available endpoints: `authorization`, `token`, `revocation`,
223
- `introspection`, `userinfo`, `jwks`, `dynamic_client_registration`.
224
- - This option requires option keys with an available endpoint and
225
- [URL options](https://api.rubyonrails.org/v6.0.3.3/classes/ActionDispatch/Routing/UrlFor.html#method-i-url_for)
226
- as value.
227
- - The default is to use the request host, just like all the other URLs in the discovery response.
228
- - This is useful when you want endpoints to use a different URL than other requests.
229
- For example, if your Doorkeeper server is behind a firewall with other servers, you might want
230
- other servers to use an "internal" URL to communicate with Doorkeeper, but you want to present
231
- an "external" URL to end-users for authentication requests. Note that this setting does not
232
- actually change the URL that your Doorkeeper server responds on - that is outside the scope of
233
- Doorkeeper.
234
-
235
- ```ruby
236
- # config/initializers/doorkeeper_openid_connect.rb
237
- Doorkeeper::OpenidConnect.configure do
238
- # ...
239
- discovery_url_options do |request|
240
- {
241
- authorization: { host: 'host.example.com' },
242
- jwks: { protocol: request.ssl? ? :https : :http }
243
- }
244
- end
245
- # ...
246
- end
247
- ```
248
-
249
- - `apply_prompt_to_non_oidc_requests`
250
- - Whether to honor the `prompt` authorization parameter (`none`, `login`, `consent`, `select_account`) on plain OAuth requests that do not include the `openid` scope.
251
- - Defaults to `false`, which preserves the historical behavior of silently ignoring `prompt` outside of OIDC requests.
252
- - `max_age` enforcement remains OIDC-only regardless of this option, since it is defined by OIDC Core.
253
-
254
- ```ruby
255
- # config/initializers/doorkeeper_openid_connect.rb
256
- Doorkeeper::OpenidConnect.configure do
257
- # ...
258
- apply_prompt_to_non_oidc_requests true
259
- # ...
260
- end
261
- ```
262
-
263
- ### Scopes
264
-
265
- To perform authentication over OpenID Connect, an OAuth client needs to request the `openid` scope. This scope needs to be enabled using either `optional_scopes` in the global Doorkeeper configuration in `config/initializers/doorkeeper.rb`, or by adding it to any OAuth application's `scope` attribute.
266
-
267
- > Note that any application defining its own scopes won't inherit the scopes defined in the initializer, so you might have to update existing applications as well.
268
- >
269
- > See [Using Scopes](https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes) in the Doorkeeper wiki for more information.
270
-
271
- #### `offline_access`
272
-
273
- Per [OIDC Core §11](https://openid.net/specs/openid-connect-core-1_0.html#OfflineAccess), the `offline_access` scope signals that the client wants a refresh token so it can access the user's resources while the user is offline. Doorkeeper's existing `use_refresh_token` block already covers the basic flow — issue a refresh token only when the client actually asked for `offline_access`:
74
+ See the [wiki](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/wiki/Configuration) for detailed configuration instructions, including:
274
75
 
275
- ```ruby
276
- # config/initializers/doorkeeper.rb
277
- Doorkeeper.configure do
278
- optional_scopes :openid, :offline_access
279
-
280
- # Issue a refresh token only when the client requests offline_access
281
- use_refresh_token do |context|
282
- context.scopes.exists?("offline_access")
283
- end
284
- end
285
- ```
286
-
287
- > **Note:** This does not automatically enforce [OIDC Core §11](https://openid.net/specs/openid-connect-core-1_0.html#OfflineAccess)'s strict requirements — for example, the OP MUST ignore `offline_access` unless `prompt=consent` is present and `response_type` returns an Authorization Code. If you need that level of enforcement, filter the scope in your `use_refresh_token` block or authorization controller override.
288
-
289
- ### Claims
290
-
291
- Claims can be defined in a `claims` block inside `config/initializers/doorkeeper_openid_connect.rb`:
292
-
293
- ```ruby
294
- Doorkeeper::OpenidConnect.configure do
295
- claims do
296
- claim :email do |resource_owner|
297
- resource_owner.email
298
- end
299
-
300
- claim :full_name do |resource_owner|
301
- "#{resource_owner.first_name} #{resource_owner.last_name}"
302
- end
303
-
304
- claim :preferred_username, scope: :openid do |resource_owner, scopes, access_token|
305
- # Pass the resource_owner's preferred_username if the application has
306
- # `profile` scope access. Otherwise, provide a more generic alternative.
307
- scopes.exists?(:profile) ? resource_owner.preferred_username : "summer-sun-9449"
308
- end
309
-
310
- claim :groups, response: [:id_token, :user_info] do |resource_owner|
311
- resource_owner.groups
312
- end
313
- end
314
- end
315
- ```
316
-
317
- Each claim block will be passed:
318
-
319
- - the `resource_owner`, which is the return value of `resource_owner_authenticator` in your initializer
320
- - the `scopes` granted by the access token, which is an instance of `Doorkeeper::OAuth::Scopes`
321
- - the `access_token` itself, which is an instance of `Doorkeeper::AccessToken`
322
-
323
- By default all custom claims are only returned from the `UserInfo` endpoint and not included in the ID token. You can optionally pass a `response:` keyword with one or both of the symbols `:id_token` or `:user_info` to specify where the claim should be returned.
324
-
325
- You can also pass a `scope:` keyword argument on each claim to specify which OAuth scope should be required to access the claim. If you define any of the defined [Standard Claims](http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims) they will by default use their [corresponding scopes](http://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims) (`profile`, `email`, `address` and `phone`), and any other claims will by default use the `profile` scope. Again, to use any of these scopes you need to enable them as described above.
326
-
327
- You can also pass an array of scopes, in which case the claim is returned whenever the access token grants any of the listed scopes. This is useful when you want to expose the same claim under both a standard scope and an aggregate scope:
328
-
329
- ``` ruby
330
- claim :given_name, scope: [:profile, :all_data] do |user|
331
- user.first_name
332
- end
333
-
334
- claim :email, scope: [:email, :all_data] do |user|
335
- user.email
336
- end
337
- ```
338
-
339
- #### Authentication Context (`acr`) and Methods (`amr`)
340
-
341
- The `claim` DSL also handles standard top-level ID Token claims such as [`acr`](http://openid.net/specs/openid-connect-core-1_0.html#IDToken) (Authentication Context Class Reference) and [`amr`](https://www.rfc-editor.org/rfc/rfc8176) (Authentication Methods References) — commonly used to expose MFA status to clients:
342
-
343
- ```ruby
344
- claims do
345
- claim :acr, response: [:id_token, :user_info], scope: :openid do |resource_owner|
346
- # Single string — e.g. a URI like "urn:mace:incommon:iap:silver",
347
- # or a numeric Level of Assurance "1".."4" per ISO/IEC 29115.
348
- resource_owner.mfa_enabled? ? "2" : "1"
349
- end
350
-
351
- claim :amr, response: [:id_token, :user_info], scope: :openid do |resource_owner|
352
- # Array of strings, per RFC 8176.
353
- methods = ["pwd"]
354
- methods << "mfa" if resource_owner.mfa_enabled?
355
- methods << "otp" if resource_owner.last_login_used_totp?
356
- methods
357
- end
358
- end
359
- ```
360
-
361
- Two defaults are worth calling out because they bite silently:
362
-
363
- - **`response: [:id_token, :user_info]`** — custom claims default to UserInfo only, but relying parties usually expect `acr` / `amr` on the ID Token.
364
- - **`scope: :openid`** — without it, non-standard claims fall back to the `profile` scope and disappear for clients that only requested `openid`.
365
-
366
- Claim names you declare here are automatically advertised under `claims_supported` in the discovery document. The list of advertised `acr` values (`acr_values_supported`) is not currently generated.
367
-
368
-
369
- ### Routes
370
-
371
- The installation generator will update your `config/routes.rb` to define all required routes:
372
-
373
- ``` ruby
374
- Rails.application.routes.draw do
375
- use_doorkeeper_openid_connect
376
- # your routes
377
- end
378
- ```
379
-
380
- This will mount the following routes:
381
-
382
- ```
383
- GET /oauth/userinfo
384
- POST /oauth/userinfo
385
- GET /oauth/discovery/keys
386
- GET /.well-known/openid-configuration
387
- GET /.well-known/oauth-authorization-server
388
- GET /.well-known/webfinger
389
- ```
390
-
391
- With the exception of the hard-coded `/.well-known` paths (see [RFC 5785](https://tools.ietf.org/html/rfc5785)) you can customize routes in the same way as with Doorkeeper, please refer to [this page on their wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Customizing-routes#version--05-1).
392
-
393
- #### Customizing the `jwks_uri` path in the discovery document
394
-
395
- [`discovery_url_options`](#configuration) lets you tweak the host, protocol, or port of the published `jwks_uri`, but not the path itself. To advertise a custom path — while keeping `/oauth/discovery/keys` working for existing clients during a rollover — mount the discovery controller at the new path and re-point the `oauth_discovery_keys_url` helper at it via [`direct`](https://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/CustomUrlHelpers.html#method-i-direct):
396
-
397
- ```ruby
398
- # config/routes.rb
399
- Rails.application.routes.draw do
400
- use_doorkeeper_openid_connect
401
-
402
- # 1. Mount the custom path under a non-conflicting helper name
403
- get "/-/jwks",
404
- to: "doorkeeper/openid_connect/discovery#keys",
405
- as: :custom_jwks
406
-
407
- # 2. Re-point oauth_discovery_keys_url at the new path
408
- direct(:oauth_discovery_keys) { |opts| custom_jwks_url(opts) }
409
- end
410
- ```
411
-
412
- After this, `.well-known/openid-configuration` returns `"jwks_uri": "https://example.com/-/jwks"`, and the original `/oauth/discovery/keys` route still responds (handy during a rollover).
413
-
414
- > [!Note]
415
- > A naive `match "/-/jwks", ..., as: :oauth_discovery_keys` won't work — Rails has refused to reuse a route name [since 4.0](https://github.com/rails/rails/commit/a2b7c0e69d) and raises `ArgumentError: Invalid route name, already in use: 'oauth_discovery_keys'`. The `direct` helper sidesteps this by overriding the URL helper itself rather than re-declaring the route name.
416
-
417
- #### Mounting under multiple namespaces (multiple resource owner models)
418
-
419
- If your app authenticates more than one kind of resource owner (e.g. a `User`
420
- and a `Customer` Devise model) you may want to mount Doorkeeper — and this engine
421
- — more than once, each under its own namespace:
422
-
423
- ```ruby
424
- # config/routes.rb
425
- Rails.application.routes.draw do
426
- scope :users, as: :users do
427
- use_doorkeeper { controllers authorizations: "users/authorizations" }
428
- use_doorkeeper_openid_connect
429
- end
430
-
431
- scope :customers, as: :customers do
432
- use_doorkeeper { controllers authorizations: "customers/authorizations" }
433
- use_doorkeeper_openid_connect
434
- end
435
- end
436
- ```
437
-
438
- Most of the request flow is model-agnostic: the `resource_owner_authenticator`
439
- block can dispatch on whichever owner is signed in (`current_user ||
440
- current_customer`), and claims / userinfo / ID token generation follow from
441
- whatever it returns.
442
-
443
- The one piece that needs attention is the **discovery document**.
444
- [`DiscoveryController#provider_response`](app/controllers/doorkeeper/openid_connect/discovery_controller.rb)
445
- builds the published endpoints by calling named route helpers
446
- (`oauth_authorization_url`, `oauth_token_url`, …) directly. The
447
- [`discovery_url_options`](#configuration) setting (added in #126) lets you
448
- override the `host` / `protocol` / `port` of those URLs, but not *which* named
449
- helper is resolved — so under multiple mounts every namespace's discovery
450
- document would point at the same set of endpoints.
451
-
452
- The idiomatic fix is to subclass the discovery controller per namespace and
453
- re-point the helper calls at that namespace's routes:
454
-
455
- ```ruby
456
- # app/controllers/users/discovery_controller.rb
457
- module Users
458
- class DiscoveryController < Doorkeeper::OpenidConnect::DiscoveryController
459
- private
460
-
461
- # Re-point each helper used by `provider_response` at the namespaced route.
462
- def oauth_authorization_url(opts = {})
463
- users_oauth_authorization_url(opts)
464
- end
465
-
466
- def oauth_token_url(opts = {})
467
- users_oauth_token_url(opts)
468
- end
469
-
470
- def oauth_revoke_url(opts = {})
471
- users_oauth_revoke_url(opts)
472
- end
473
-
474
- def oauth_userinfo_url(opts = {})
475
- users_oauth_userinfo_url(opts)
476
- end
477
-
478
- def oauth_discovery_keys_url(opts = {})
479
- users_oauth_discovery_keys_url(opts)
480
- end
481
-
482
- # ...and `oauth_introspect_url` / `oauth_dynamic_client_registration_url`
483
- # if you advertise those.
484
- end
485
- end
486
- ```
487
-
488
- ```ruby
489
- # config/routes.rb (inside the `:users` scope)
490
- get "/.well-known/openid-configuration",
491
- to: "users/discovery#provider", as: :users_openid_connect_config
492
- ```
493
-
494
- Repeat for the `customers` namespace. Each `.well-known/openid-configuration`
495
- then advertises the endpoints for its own namespace.
496
-
497
- > [!Note]
498
- > See [#192](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/issues/192)
499
- > for the original discussion. First-class multi-mount support is not provided
500
- > out of the box; the per-namespace controller override above is the supported
501
- > extension pattern for now.
502
-
503
- ### Nonces
504
-
505
- To support clients who send nonces you have to tweak Doorkeeper's authorization view so the parameter is passed on.
506
-
507
- If you don't already have custom templates, run this generator in your Rails application to add them:
508
-
509
- ```sh
510
- rails generate doorkeeper:views
511
- ```
512
-
513
- Then tweak the template as follows:
514
-
515
- ```patch
516
- --- i/app/views/doorkeeper/authorizations/new.html.erb
517
- +++ w/app/views/doorkeeper/authorizations/new.html.erb
518
- @@ -26,6 +26,7 @@
519
- <%= hidden_field_tag :state, @pre_auth.state %>
520
- <%= hidden_field_tag :response_type, @pre_auth.response_type %>
521
- <%= hidden_field_tag :scope, @pre_auth.scope %>
522
- + <%= hidden_field_tag :nonce, @pre_auth.nonce %>
523
- <%= submit_tag t('doorkeeper.authorizations.buttons.authorize'), class: "btn btn-success btn-lg btn-block" %>
524
- <% end %>
525
- <%= form_tag oauth_authorization_path, method: :delete do %>
526
- @@ -34,6 +35,7 @@
527
- <%= hidden_field_tag :state, @pre_auth.state %>
528
- <%= hidden_field_tag :response_type, @pre_auth.response_type %>
529
- <%= hidden_field_tag :scope, @pre_auth.scope %>
530
- + <%= hidden_field_tag :nonce, @pre_auth.nonce %>
531
- <%= submit_tag t('doorkeeper.authorizations.buttons.deny'), class: "btn btn-danger btn-lg btn-block" %>
532
- <% end %>
533
- </div>
534
- ```
535
-
536
- ### Internationalization (I18n)
537
-
538
- We use Rails locale files for error messages and scope descriptions, see [config/locales/en.yml](config/locales/en.yml). You can override these by adding them to your own translations in `config/locale`.
539
-
540
- ### Dynamic Client Registration
541
-
542
- This gem supports [OpenID Connect Dynamic Client Registration 1.0](https://openid.net/specs/openid-connect-registration-1_0.html) based on [RFC 7591](https://www.rfc-editor.org/rfc/rfc7591).
543
-
544
- To enable dynamic client registration, add the following to `config/initializers/doorkeeper_openid_connect.rb`:
545
-
546
- ```ruby
547
- Doorkeeper::OpenidConnect.configure do
548
- # ...
549
- dynamic_client_registration true
550
- # ...
551
- end
552
- ```
553
-
554
- This exposes a `POST /oauth/registration` endpoint where OAuth clients can register themselves.
555
-
556
- #### Supported parameters
557
-
558
- The registration endpoint currently accepts the following [RFC 7591 §2](https://www.rfc-editor.org/rfc/rfc7591#section-2) parameters:
559
-
560
- | Parameter | Description |
561
- | --- | --- |
562
- | `client_name` | Human-readable name of the client |
563
- | `redirect_uris` | Array of redirection URIs |
564
- | `scope` | Space-delimited list of requested scopes |
565
- | `token_endpoint_auth_method` | Requested authentication method. Defaults to `client_secret_basic`. `none` is always allowed (and registers a public client); other allowed values depend on the host application's Doorkeeper `client_credentials_methods` configuration. Unsupported values are rejected with `invalid_client_metadata`. |
566
- | `application_type` | Client type: `web` (default) or `native`, per [OpenID Connect Discovery 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html). Unsupported values are rejected with `invalid_client_metadata`. |
567
- | `response_types` | Array of OAuth 2.0 response types the client will use (e.g. `["code"]`). Must be a subset of the server's supported response types. Defaults to the server's full set when omitted. |
568
- | `grant_types` | Array of OAuth 2.0 grant types the client will use (e.g. `["authorization_code"]`). Must be a subset of the server's supported grant types. Defaults to the server's full set when omitted. |
569
-
570
- When `token_endpoint_auth_method` is set to `none`, the client is registered as **public** (i.e. `confidential: false`). For all other values — or when the parameter is omitted — the client is registered as **confidential**, matching the RFC 7591 default of `client_secret_basic`.
571
-
572
- Other RFC 7591 parameters (e.g. `client_uri`, `logo_uri`, `contacts`) require schema additions to `oauth_applications` and are not yet supported.
573
-
574
- #### Authorization
575
-
576
- By default, the registration endpoint is open to any request. To require authorization (e.g. an Initial Access Token per [RFC 7591 §3.1](https://www.rfc-editor.org/rfc/rfc7591#section-3.1)), configure `authorize_dynamic_client_registration`:
577
-
578
- ```ruby
579
- Doorkeeper::OpenidConnect.configure do
580
- # ...
581
- dynamic_client_registration true
582
- authorize_dynamic_client_registration do
583
- provided = request.headers["Authorization"].to_s
584
- expected = "Bearer #{ENV['DCR_INITIAL_ACCESS_TOKEN']}"
585
- # Use a constant-time comparison to avoid leaking the token via timing.
586
- # Digesting first keeps the comparison fixed-length so the token's length
587
- # isn't leaked either.
588
- ActiveSupport::SecurityUtils.secure_compare(
589
- Digest::SHA256.hexdigest(provided),
590
- Digest::SHA256.hexdigest(expected),
591
- )
592
- end
593
- # ...
594
- end
595
- ```
596
-
597
- The block is evaluated in the controller scope (with access to `request`, `params`, `request.headers`, etc.). Return a truthy value to allow the request, or a falsy value to reject it with `401 invalid_token`.
598
-
599
- When not configured (default), the endpoint remains open for backward compatibility.
76
+ - [Scopes](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/wiki/Scopes)
77
+ - [Claims](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/wiki/Claims)
78
+ - [Routes](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/wiki/Routes)
79
+ - [Nonces](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/wiki/Nonces)
80
+ - [Internationalization (I18n)](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/wiki/I18n)
81
+ - [Dynamic Client Registration](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/wiki/Dynamic-Client-Registration)
600
82
 
601
83
  ## Development
602
84
 
@@ -72,6 +72,10 @@ module Doorkeeper
72
72
  if registration.confidential_client?
73
73
  response[:client_secret] =
74
74
  doorkeeper_application.plaintext_secret || doorkeeper_application.secret
75
+ # RFC 7591 §3.2.1 / OIDC Dynamic Client Registration 1.0 §3.2:
76
+ # client_secret_expires_at is REQUIRED when a client_secret is issued.
77
+ # Doorkeeper secrets never expire, so the value is 0 (no expiration).
78
+ response[:client_secret_expires_at] = 0
75
79
  end
76
80
 
77
81
  response
@@ -24,3 +24,5 @@ en:
24
24
  signing_key_not_configured: 'Doorkeeper::OpenidConnect.configure.signing_key must resolve to at least one key.'
25
25
  issuer_not_configured: 'Doorkeeper::OpenidConnect.configure.issuer must resolve to a non-blank value.'
26
26
  dynamic_client_registration_unauthorized: 'Authorization required for client registration'
27
+ # ID Token claim error messages
28
+ missing_required_claim: 'Required ID Token claim `%{claim}` is missing or blank'
@@ -54,6 +54,7 @@ module Doorkeeper
54
54
  }
55
55
 
56
56
  option :auth_time_from_session, default: nil
57
+ option :auth_time_from_access_token, default: nil
57
58
 
58
59
  option :reauthenticate_resource_owner, default: lambda { |*_|
59
60
  raise Errors::InvalidConfiguration, I18n.translate("doorkeeper.openid_connect.errors.messages.reauthenticate_resource_owner_not_configured")
@@ -12,6 +12,18 @@ module Doorkeeper
12
12
  # internal errors
13
13
  class InvalidConfiguration < OpenidConnectError; end
14
14
 
15
+ # Raised when a REQUIRED ID Token claim (OIDC Core §2: iss/sub/aud/exp/iat)
16
+ # resolves to a blank value, which would otherwise be silently dropped and
17
+ # produce a non-conformant ID Token.
18
+ class MissingRequiredClaim < OpenidConnectError
19
+ attr_reader :claim
20
+
21
+ def initialize(claim)
22
+ @claim = claim
23
+ super(I18n.translate("doorkeeper.openid_connect.errors.messages.missing_required_claim", claim: claim))
24
+ end
25
+ end
26
+
15
27
  class MissingConfiguration < OpenidConnectError
16
28
  def initialize
17
29
  super("Configuration for Doorkeeper OpenID Connect missing. Do you have doorkeeper_openid_connect initializer?")
@@ -125,7 +125,7 @@ module Doorkeeper
125
125
  render :new
126
126
  end
127
127
  when "select_account"
128
- select_account_for_oidc_resource_owner(owner) if owner
128
+ select_account_for_oidc_resource_owner(owner)
129
129
  when "create"
130
130
  # NOTE: not supported, but not raise error.
131
131
  else
@@ -5,6 +5,10 @@ module Doorkeeper
5
5
  class IdToken
6
6
  include ActiveModel::Validations
7
7
 
8
+ # OIDC Core 1.0 §2 — these claims are REQUIRED in every ID Token, so they
9
+ # must never be silently dropped when blank.
10
+ REQUIRED_CLAIMS = %i[iss sub aud exp iat].freeze
11
+
8
12
  attr_reader :nonce
9
13
 
10
14
  def initialize(access_token, nonce = nil, expires_in = Doorkeeper::OpenidConnect.configuration.expiration)
@@ -31,7 +35,19 @@ module Doorkeeper
31
35
  end
32
36
 
33
37
  def as_json(*_)
34
- claims.reject { |_, value| value.nil? || value == "" }
38
+ claims.each_with_object({}) do |(key, value), result|
39
+ blank = value.nil? || value == ""
40
+
41
+ if blank
42
+ # A REQUIRED claim must never be silently omitted; surface the
43
+ # misconfiguration instead of issuing a non-conformant ID Token.
44
+ raise Errors::MissingRequiredClaim, key if REQUIRED_CLAIMS.include?(key)
45
+
46
+ next
47
+ end
48
+
49
+ result[key] = value
50
+ end
35
51
  end
36
52
 
37
53
  def as_jws_token
@@ -78,7 +94,13 @@ module Doorkeeper
78
94
  end
79
95
 
80
96
  def auth_time
81
- Doorkeeper::OpenidConnect.configuration.auth_time_from_resource_owner.call(@resource_owner).try(:to_i)
97
+ config = Doorkeeper::OpenidConnect.configuration
98
+
99
+ if config.auth_time_from_access_token
100
+ config.auth_time_from_access_token.call(@access_token).try(:to_i)
101
+ else
102
+ config.auth_time_from_resource_owner.call(@resource_owner).try(:to_i)
103
+ end
82
104
  rescue Errors::InvalidConfiguration
83
105
  nil
84
106
  end
@@ -11,6 +11,18 @@ module Doorkeeper
11
11
  included do
12
12
  self.table_name = "#{table_name_prefix}oauth_openid_requests#{table_name_suffix}".to_sym
13
13
 
14
+ # Legacy multi-database support: older Doorkeeper releases let
15
+ # users route the ORM models to a separate connection via
16
+ # `active_record_options[:establish_connection]`. Doorkeeper
17
+ # 5.9.x no longer exposes `active_record_options`, so the guard
18
+ # makes this a no-op there. It used to live in the ORM adapter's
19
+ # `run_hooks`; wiring it from the model's own `included` block
20
+ # keeps it off the re-entrant `on_load(:active_record)` path.
21
+ if Doorkeeper.configuration.respond_to?(:active_record_options) &&
22
+ (connection_options = Doorkeeper.configuration.active_record_options[:establish_connection])
23
+ establish_connection(connection_options)
24
+ end
25
+
14
26
  validates :access_grant_id, :nonce, presence: true
15
27
 
16
28
  if Gem.loaded_specs["doorkeeper"].version >= Gem::Version.create("5.5.0")
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/lazy_load_hooks"
4
-
5
3
  module Doorkeeper
6
4
  module OpenidConnect
7
5
  autoload :AccessGrant, "doorkeeper/openid_connect/orm/active_record/access_grant"
@@ -14,51 +12,43 @@ module Doorkeeper
14
12
  "doorkeeper/openid_connect/orm/active_record/mixins/openid_request"
15
13
  end
16
14
 
17
- def run_hooks
18
- super
19
-
20
- ActiveSupport.on_load(:active_record) do
21
- require "doorkeeper/openid_connect/orm/active_record/access_grant"
22
- require "doorkeeper/openid_connect/orm/active_record/request"
23
-
24
- if Gem.loaded_specs["doorkeeper"].version >= Gem::Version.create("5.5.0")
25
- Doorkeeper.config.access_grant_model.prepend Doorkeeper::OpenidConnect::AccessGrant
26
- else
27
- Doorkeeper::AccessGrant.prepend Doorkeeper::OpenidConnect::AccessGrant
28
- end
29
-
30
- if Doorkeeper.configuration.respond_to?(:active_record_options) && Doorkeeper.configuration.active_record_options[:establish_connection]
31
- [Doorkeeper::OpenidConnect.configuration.open_id_request_model].each do |c|
32
- c.send :establish_connection,
33
- Doorkeeper.configuration.active_record_options[:establish_connection]
34
- end
35
- end
36
- end
37
- end
38
-
39
- def initialize_models!
40
- super
41
- ActiveSupport.on_load(:active_record) do
42
- require "doorkeeper/openid_connect/orm/active_record/access_grant"
43
- require "doorkeeper/openid_connect/orm/active_record/request"
44
-
45
- if Gem.loaded_specs["doorkeeper"].version >= Gem::Version.create("5.5.0")
46
- Doorkeeper.config.access_grant_model.prepend Doorkeeper::OpenidConnect::AccessGrant
47
- else
48
- Doorkeeper::AccessGrant.prepend Doorkeeper::OpenidConnect::AccessGrant
49
- end
50
-
51
- if Doorkeeper.configuration.active_record_options[:establish_connection]
52
- [Doorkeeper::OpenidConnect.configuration.open_id_request_model].each do |c|
53
- c.send :establish_connection,
54
- Doorkeeper.configuration.active_record_options[:establish_connection]
55
- end
56
- end
15
+ # Prepended onto the singleton class of Doorkeeper's AccessGrant
16
+ # mixin so that every model which includes
17
+ # `Doorkeeper::Orm::ActiveRecord::Mixins::AccessGrant` — the default
18
+ # `Doorkeeper::AccessGrant` as well as any (possibly namespaced)
19
+ # custom access grant model — also gains the OpenID Connect
20
+ # `openid_request` association.
21
+ #
22
+ # The association is wired from the mixin's `included` callback, at
23
+ # the moment the host model is loaded: `base` is the model class
24
+ # itself, handed to us by Ruby. Nothing reaches out to constantize
25
+ # the configured grant class, so the re-entrant
26
+ # `ActiveSupport.on_load(:active_record)` window that broke
27
+ # namespaced custom models is gone.
28
+ #
29
+ # Background: doorkeeper-openid_connect v1.10.0 (#241) wrapped the
30
+ # grant-model prepend in `ActiveSupport.on_load(:active_record)`,
31
+ # following doorkeeper #1804. doorkeeper later reverted that in
32
+ # #1830 (v5.9.2) because the hook fires while `ActiveRecord::Base`
33
+ # is first loaded — e.g. mid-evaluation of
34
+ # `class ApplicationRecord < ActiveRecord::Base` — at which point
35
+ # constantizing `Auth::OAuthAccessGrant < ApplicationRecord` raises
36
+ # `NameError: uninitialized constant Auth::ApplicationRecord` (#306).
37
+ # We follow the same fix: wire from the mixin instead of on_load.
38
+ module AccessGrantExtension
39
+ def included(base)
40
+ super
41
+ # `base` is a Module (not the model) when the mixin is included
42
+ # into an intermediate ActiveSupport::Concern; the concern defers
43
+ # the include, so this hook fires again with the model class.
44
+ base.prepend(OpenidConnect::AccessGrant) if base.is_a?(Class)
57
45
  end
58
46
  end
59
47
  end
60
48
  end
61
49
  end
62
50
 
63
- Orm::ActiveRecord.singleton_class.send :prepend, OpenidConnect::Orm::ActiveRecord
51
+ Orm::ActiveRecord::Mixins::AccessGrant.singleton_class.prepend(
52
+ OpenidConnect::Orm::ActiveRecord::AccessGrantExtension,
53
+ )
64
54
  end
@@ -4,7 +4,7 @@ module Doorkeeper
4
4
  module OpenidConnect
5
5
  MAJOR = 1
6
6
  MINOR = 10
7
- TINY = 1
7
+ TINY = 3
8
8
  PRE = nil
9
9
 
10
10
  # Full version number
@@ -57,6 +57,18 @@ Doorkeeper::OpenidConnect.configure do
57
57
  # session[:auth_time]
58
58
  # end
59
59
 
60
+ # Advanced:
61
+ # If you store `auth_time` in a custom authentication context record linked
62
+ # to the access token, you can configure a block like below to derive it
63
+ # from the access token instead of `auth_time_from_resource_owner`.
64
+ #
65
+ # This allows you to track `auth_time` per grant instead of per user,
66
+ # but requires more custom implementation on your part.
67
+ #
68
+ # auth_time_from_access_token do |access_token|
69
+ # access_token.your_custom_authentication_context_record.auth_time
70
+ # end
71
+
60
72
  reauthenticate_resource_owner do |resource_owner, return_to|
61
73
  # Example implementation:
62
74
  # store_location_for resource_owner, return_to
@@ -64,9 +76,11 @@ Doorkeeper::OpenidConnect.configure do
64
76
  # redirect_to new_user_session_url
65
77
  end
66
78
 
67
- select_account_for_resource_owner do |resource_owner, return_to|
79
+ select_account_for_resource_owner do |resource_owner_or_nil, return_to|
68
80
  # Example implementation:
69
- # store_location_for resource_owner, return_to
81
+ # if resource_owner_or_nil
82
+ # store_location_for resource_owner_or_nil, return_to
83
+ # end
70
84
  # redirect_to account_select_url
71
85
  end
72
86
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doorkeeper-openid_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.1
4
+ version: 1.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Dengler
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2026-06-03 00:00:00.000000000 Z
13
+ date: 2026-06-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: doorkeeper
@@ -245,7 +245,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
245
  requirements:
246
246
  - - ">="
247
247
  - !ruby/object:Gem::Version
248
- version: '3.1'
248
+ version: '3.2'
249
249
  required_rubygems_version: !ruby/object:Gem::Requirement
250
250
  requirements:
251
251
  - - ">="