-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow adding digital signatures to webhook headers
- 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.
- Loading branch information
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright © WireMock.Net | ||
|
||
using System.Threading.Tasks; | ||
using WireMock.Util; | ||
|
||
namespace WireMock.Models; | ||
|
||
/// <summary> | ||
/// A delegate encapsulating logic for fetching or generating a private key. | ||
/// </summary> | ||
/// <returns>An async task containing the value of the private key.</returns> | ||
public delegate Task<string> PrivateKeyCallback(); | ||
|
||
/// <summary> | ||
/// A delegate encapsulating logic for fetching or generating a digital signature. | ||
/// </summary> | ||
/// <param name="privateKey">The value of the private key returned by <see cref="PrivateKeyCallback"/>.</param> | ||
/// <param name="bodyData">The body data associated with the request.</param> | ||
/// <returns>An async task containing the value of the digital signature.</returns> | ||
public delegate Task<string> DigitalSignatureCallback(string privateKey, IBodyData? bodyData); | ||
|
||
/// <summary> | ||
/// An interface encapsulating logic for generating a digital signature. | ||
/// </summary> | ||
public interface IDigitalSignature | ||
{ | ||
/// <summary> | ||
/// The header name to use for the digital signature. | ||
/// </summary> | ||
string HeaderName { get; set; } | ||
|
||
/// <summary> | ||
/// The callback used to fetch or generate the private key. | ||
/// </summary> | ||
PrivateKeyCallback PrivateKeyCallback { get; set; } | ||
|
||
/// <summary> | ||
/// The callback used to fetch or generate the digital signature. | ||
/// </summary> | ||
DigitalSignatureCallback DigitalSignatureCallback { get; set; } | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright © WireMock.Net | ||
|
||
using System.Threading.Tasks; | ||
|
||
namespace WireMock.Models; | ||
|
||
/// <summary> | ||
/// A class encapsulating logic for generating a digital signature. | ||
/// </summary> | ||
public class DigitalSignature : IDigitalSignature | ||
{ | ||
/// <inheritdoc/> | ||
public string HeaderName { get; set; } = ""; | ||
|
||
/// <inheritdoc/> | ||
public PrivateKeyCallback PrivateKeyCallback { get; set; } = async () => await Task.FromResult(""); | ||
|
||
/// <inheritdoc/> | ||
public DigitalSignatureCallback DigitalSignatureCallback { get; set; } = async (privateKey, bodyData) => await Task.FromResult(""); | ||
} |
This file contains 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