Repository navigation
Add after_request_phase callback hook - #1147
Merged
BobbyMcWho merged 3 commits intoOct 1, 2025
Merged
BobbyMcWho merged 3 commits into
BobbyMcWho merged 3 commits into
Conversation
There are cases when you want to execute some code after the request phase but before the callback phase. For example, you might want to perform some logging, access the result from the request phase, or modify the environment. This commit adds an `after_request_phase` hook to the OmniAuth builder, allowing developers to define custom behavior after the request phase is completed. This hook is executed after the request phase but before the callback phase, providing a convenient place to handle any necessary logic.
Contributor
Author
|
@BobbyMcWho Do you have the capacity to review this PR? Let me know if I can do anything to clarify or help. 🙏 |
Contributor
Author
|
@BobbyMcWho Here is a gentle nudge regarding this PR. Do you have the bandwidth to take a look at this? |
BobbyMcWho
requested changes
Oct 1, 2025
BobbyMcWho
reviewed
Oct 1, 2025
BobbyMcWho
self-requested a review
October 1, 2025 16:58
BobbyMcWho
approved these changes
Oct 1, 2025
Contributor
Author
|
@BobbyMcWho Thanks for reviewing, approving and also releasing a version. 🙇 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
OmniAuth currently provides several lifecycle hooks (
before_request_phase,before_callback_phase,before_options_phase) that allow developers to execute custom logic before the different phases of an authentication flow. However, there is currently no hook for executing custom logic after the request phase completes.This limitation becomes problematic when you need to, for example:
Without an
after_request_phasehook, developers are forced to:Solution
This PR introduces an
after_request_phasecallback that mirrors the existingbefore_request_phasepattern, providing a clean and consistent API for post-request-phase logic.Changes
after_request_phaseconfiguration option toOmniAuth::Configurationafter_request_phasemethod toOmniAuth::Builderfor easy configurationrequest_callandmock_request_call)Usage Example
Testing
All existing tests pass, and new tests have been added to cover:
Why This Matters
This feature completes OmniAuth's lifecycle hook ecosystem, providing developers with the full set of tools needed to implement robust, production-ready authentication flows. It follows established patterns in the codebase and maintains the same level of reliability and test coverage as existing hooks.
The implementation is non-intrusive and maintains full backward compatibility while opening up new possibilities for monitoring, cleanup, and custom logic execution.
Example Use Case: GitLab Step-Up Authentication
GitLab's step-up authentication requires capturing the OAuth
stateparameter after it's generated to validate returning users. The OpenID Connect strategy generates this UUID during the request phase inauthorize_uriby callingnew_state, but no existing hook allows access to this value after generation.The Problem:
before_request_phase: Runs beforestategenerationbefore_callback_phase: Runs after user returns with a callback from IdPstateafter generation but before redirectThe Solution:
This enables GitLab to securely capture and store the generated state parameter for step-up authentication validation without monkey-patching OmniAuth internals.