Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom form post writer #58

Merged
merged 1 commit into from
Mar 13, 2024
Merged

Conversation

james-d-elliott
Copy link
Member

@james-d-elliott james-d-elliott commented Mar 13, 2024

This implements a custom form post response writer interface into the configurator.

Summary by CodeRabbit

  • New Features
    • Introduced support for Custom Form Post Response Writer for enhanced handling of form post responses in authorization flows.
  • Refactor
    • Updated the mechanism for writing form post responses across various components to utilize the new FormPostResponseWriter.
    • Added a new interface FormPostResponseProvider to standardize the retrieval of form post response writers.
  • Tests
    • Adjusted tests to reflect the new method of handling form post responses.

This implements a custom form post response writer interface into the configurator.
@james-d-elliott james-d-elliott requested a review from a team as a code owner March 13, 2024 00:04
Copy link

coderabbitai bot commented Mar 13, 2024

Walkthrough

The recent updates bring a new approach to handling form post responses in the application. A significant shift replaces the WriteAuthorizeFormPostResponse function with a more flexible FormPostResponseWriter type and its default implementation. This change is complemented by the introduction of the FormPostResponseProvider interface, ensuring a customizable mechanism for writing form post responses, thus enhancing the application's extensibility and maintainability.

Changes

File(s) Summary
README.md Added support for Custom Form Post Response Writer in the list of features.
authorize_helper.go, .../authorize_form_post_test.go, response_handler.go Replaced WriteAuthorizeFormPostResponse with FormPostResponseWriter and its default function, altering form post response handling. Modified related functions to accommodate the new approach.
authorize_helper_test.go Updated the test to use the new DefaultFormPostResponseWriter with a different parameter order.
config.go, config_default.go, fosite.go Introduced FormPostResponseProvider interface and updated Config struct and methods to support the new form post response writing mechanism.

🐇✨
In fields of code where brackets bloom,
A change did stir, dispelling gloom.
With types anew and structures grand,
Form posts respond to our command.
Through interfaces wide, our code does hop,
Thanks to the team, our progress won't stop.
🚀🌟

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0752a2d and 9699eea.
Files selected for processing (8)
  • README.md (1 hunks)
  • authorize_helper.go (1 hunks)
  • authorize_helper_test.go (1 hunks)
  • config.go (1 hunks)
  • config_default.go (3 hunks)
  • fosite.go (1 hunks)
  • integration/authorize_form_post_test.go (1 hunks)
  • response_handler.go (2 hunks)
Check Runs (3)
test completed (1)
format completed (1)
generate completed (5)
Additional comments: 10
fosite.go (1)
  • 158-158: The addition of FormPostResponseProvider to the Configurator interface aligns well with the PR's objectives. Ensure that the implementation of this interface is consistent and integrates smoothly with existing functionalities across the application.
response_handler.go (2)
  • 114-114: The modification to use FormPostResponseProvider for writing form post responses in handleWriteAuthorizeResponse is a significant improvement. Consider adding documentation or comments explaining the rationale behind this change for future maintainability.
  • 225-225: The addition of FormPostResponseProvider to ResponseModeHandlerConfigurator is crucial for the new form post response handling mechanism. Ensure that all implementations of ResponseModeHandlerConfigurator now properly implement this interface.
README.md (1)
  • 72-72: The addition of "Custom Form Post Response Writer" to the list of features is a valuable update. Consider providing more context or a brief description of this feature to help readers understand its significance and usage.
authorize_helper.go (2)
  • 192-192: The introduction of the FormPostResponseWriter type is a significant enhancement. Consider adding documentation or comments explaining its purpose and usage to ensure clarity and maintainability.
  • 194-194: The DefaultFormPostResponseWriter function provides a valuable default implementation. Ensure that it is accompanied by comprehensive documentation or comments detailing its behavior and intended use.
config.go (1)
  • 283-288: The introduction of the FormPostResponseProvider interface with the GetFormPostResponseWriter method is a commendable addition. It aligns with the PR's goal of enhancing form post response handling by offering a customizable approach. This change promotes flexibility and adaptability in managing form post responses, which is beneficial for the application's overall architecture.
config_default.go (3)
  • 149-149: The addition of the FormPostResponseWriter field to the Config struct introduces a new way to handle form post responses, aligning with the PR's objectives. Ensure that the default value of this field is properly handled to avoid nil pointer dereferences.
  • 278-284: The implementation of GetFormPostResponseWriter method correctly checks for a nil FormPostResponseWriter and assigns the DefaultFormPostResponseWriter if necessary. This ensures safe usage of the FormPostResponseWriter throughout the application.
  • 632-632: The interface _FormPostResponseProvider is correctly implemented by the Config struct, ensuring that the Config can be used wherever a FormPostResponseProvider is required. This change supports the PR's goal of enhancing form post response handling.

authorize_helper_test.go Show resolved Hide resolved
@@ -254,17 +254,15 @@ func (m *DecoratedFormPostResponse) ResponseModes() oauth2.ResponseModeTypes {
func (m *DecoratedFormPostResponse) WriteAuthorizeResponse(ctx context.Context, rw http.ResponseWriter, ar oauth2.AuthorizeRequester, resp oauth2.AuthorizeResponder) {
rw.Header().Add(consts.HeaderContentType, consts.ContentTypeTextHTML)
resp.AddParameter("custom_param", "foo")
oauth2.WriteAuthorizeFormPostResponse(ar.GetRedirectURI().String(), resp.GetParameters(), oauth2.GetPostFormHTMLTemplate(ctx,
new(oauth2.Config)), rw)
oauth2.DefaultFormPostResponseWriter(rw, oauth2.GetPostFormHTMLTemplate(ctx, new(oauth2.Config)), ar.GetRedirectURI().String(), resp.GetParameters())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The modification to use oauth2.DefaultFormPostResponseWriter in the WriteAuthorizeResponse method of DecoratedFormPostResponse changes the way form post responses are handled. Verify that the new parameter order and function logic are correctly implemented to maintain the integrity of the integration tests.

}

func (m *DecoratedFormPostResponse) WriteAuthorizeError(ctx context.Context, rw http.ResponseWriter, ar oauth2.AuthorizeRequester, err error) {
rfc := oauth2.ErrorToRFC6749Error(err)
errors := rfc.ToValues()
errors.Set(consts.FormParameterState, ar.GetState())
errors.Add("custom_err_param", "bar")
oauth2.WriteAuthorizeFormPostResponse(ar.GetRedirectURI().String(), errors, oauth2.GetPostFormHTMLTemplate(ctx,
new(oauth2.Config)), rw)
oauth2.DefaultFormPostResponseWriter(rw, oauth2.GetPostFormHTMLTemplate(ctx, new(oauth2.Config)), ar.GetRedirectURI().String(), errors)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, the change to use oauth2.DefaultFormPostResponseWriter in the WriteAuthorizeError method must be carefully reviewed to ensure that error handling in form post responses remains effective and aligns with the expected behavior in integration tests.

@james-d-elliott james-d-elliott merged commit 43d0165 into master Mar 13, 2024
3 checks passed
@james-d-elliott james-d-elliott deleted the feat-form-post-writer branch March 13, 2024 00:16
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.

1 participant