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

Allow adding digital signatures to webhook headers #1200

Closed

Conversation

mathgr22
Copy link

Because webhook bodies and headers are transformed separately, Handlebars cannot be used to generate digital signatures using both the body and the header. This change allows the user to specify two callbacks to use to generate a digital signature for the webhook before it is sent.

- Because webhook bodies and headers are transformed separately,
  Handlebars cannot be used to generate digital signatures using both
  the body and the header. This change allows the user to specify two
  callbacks to use to generate a digital signature for the webhook
  before it is sent.
@StefH
Copy link
Collaborator

StefH commented Oct 22, 2024

@mathgr22
Thanks for this PR, however this is very specific to your use-case.

I think it's better to add functionality to support providing your own callback method to generate the complete request.

A bit look-a-like as this:
https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/ResponseBuilders/Response.WithBody.cs

@mathgr22
Copy link
Author

@StefH
You're suggesting a WebhookRequest.WithBody, or something to that effect? This was my original idea, unfortunately my tech-lead thought something specific to digital signatures was a better route. I could certainly attempt to implement something along the lines of what you suggested.

@StefH
Copy link
Collaborator

StefH commented Oct 22, 2024

Instead of WebhookRequest.WithBody, I think this should be WebhookRequest.WithXXX (I don't know a good name now)
But essentially the parameter should be a Func/Action which takes the request and maybe other fields and from that data, you should create a complete response in C# code (complete = body + headers + all else)

@mathgr22
Copy link
Author

I think the problem I'm running into here is that I want to be able to modify the headers after the body has already been transformed. After implementing a method taking an IRequestMessage as a parameter, I realized that this doesn't do anything for me, as I need the body to already have been transformed before I can generate the digital signature. Of course I could not use transformers, but it would be nice to be able to use transformers as well.

Essentially, I need something like IWebhookRequest.WithPostTransformProcess(Func<IWebhookRequest, IWebhookRequest> webhookPostProcesser) that will allow me to intercept the webhook after it's transformed, but before it's sent. This could be done through a more generalized version of the code in this PR, but I'm not too sure what the signatures should look like, etc.

@mathgr22
Copy link
Author

Or perhaps I need an event on the IWebhookRequest that runs before sending .OnBeforeSending or something.

@mathgr22 mathgr22 closed this Oct 30, 2024
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.

2 participants