fix: handle DoubleRenderError in library instead of requiring consumer workaround #233
+13
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Moves DoubleRenderError prevention from consumer callbacks into the library itself, so users no longer need to add
self.response_body = nil/@_response_body = nilin theirreauthenticate_resource_ownerandselect_account_for_resource_ownerblocks.Fixes #206
Problem
Since v1.8.11, several scenarios cause
AbstractController::DoubleRenderError:max_age+ prompt:handle_oidc_max_age_param!triggersreauthenticate_oidc_resource_owner(redirect), thenhandle_oidc_prompt_param!also renders/redirectsprompt=login consent-consentrenders:new, thenloginredirects viareauthenticate_oidc_resource_ownermax_age=0: Always triggers reauthentication, compounding with any prompt handlerThe 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 clearsresponse_bodybefore issuing a new render/redirect. Called in:reauthenticate_oidc_resource_owner- before executing the consumer's callbackselect_account_for_oidc_resource_owner- before executing the consumer's callbackhandle_oidc_prompt_param!consent branch - beforerender :newThis matches the existing pattern in
handle_oidc_error!which already clears the response body.Changes
lib/doorkeeper/openid_connect/helpers/controller.rb- addclear_oidc_response!and call it in the three locations abovespec/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 commentsAll 174 existing tests pass without the consumer-side workaround.