Skip to content

Conversation

@bvogel
Copy link

@bvogel bvogel commented Feb 12, 2026

Summary

Moves DoubleRenderError prevention from consumer callbacks into the library itself, so users no longer need to add self.response_body = nil / @_response_body = nil in their reauthenticate_resource_owner and select_account_for_resource_owner blocks.

Fixes #206

Problem

Since v1.8.11, several scenarios cause AbstractController::DoubleRenderError:

  1. max_age + prompt: handle_oidc_max_age_param! triggers reauthenticate_oidc_resource_owner (redirect), then handle_oidc_prompt_param! also renders/redirects
  2. Multiple prompt values: e.g. prompt=login consent - consent renders :new, then login redirects via reauthenticate_oidc_resource_owner
  3. max_age=0: Always triggers reauthentication, compounding with any prompt handler

The current workaround (documented in the generator template and test dummy) requires every consumer to add response clearing in their callbacks. This is error-prone and undiscoverable.

Solution

Adds a clear_oidc_response! helper that safely clears response_body before issuing a new render/redirect. Called in:

  • reauthenticate_oidc_resource_owner - before executing the consumer's callback
  • select_account_for_oidc_resource_owner - before executing the consumer's callback
  • handle_oidc_prompt_param! consent branch - before render :new

This matches the existing pattern in handle_oidc_error! which already clears the response body.

Changes

  • lib/doorkeeper/openid_connect/helpers/controller.rb - add clear_oidc_response! and call it in the three locations above
  • spec/dummy/config/initializers/doorkeeper_openid_connect.rb - remove the consumer-side workaround (no longer needed)
  • lib/generators/doorkeeper/openid_connect/templates/initializer.rb - remove the DoubleRenderError workaround comments

All 174 existing tests pass without the consumer-side workaround.

…r workaround

When multiple OIDC handlers (max_age, prompt values) trigger render/redirect
in sequence, a DoubleRenderError is raised. Previously, consumers had to add
`self.response_body = nil` in their initializer callbacks to work around this.

This moves the response clearing into the library itself via a
`clear_oidc_response!` helper called before each render/redirect in
`reauthenticate_oidc_resource_owner`, `select_account_for_oidc_resource_owner`,
and the consent branch of `handle_oidc_prompt_param!`.

Fixes doorkeeper-gem#206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

some combinations of prompt causes double rendering/redirection

2 participants