Skip to content

Commit 321a347

Browse files
committed
Implementations of the verifier middleware and a default verification service
1 parent 5ad2ba1 commit 321a347

14 files changed

+634
-98
lines changed

src/Deveel.Webhooks.Receiver.AspNetCore/Deveel.Webhooks.Receiver.AspNetCore.xml

Lines changed: 215 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Deveel.Webhooks.Receiver.AspNetCore/Webhooks/IWebhookRequestVerifier.cs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,29 @@
1515
using Microsoft.AspNetCore.Http;
1616

1717
namespace Deveel.Webhooks {
18-
/// <summary>
19-
/// A service that is used to verify a request of acknowledgement
20-
/// by the sender of a webhook, before the webhook is sent.
21-
/// </summary>
22-
/// <typeparam name="TWebhook">
23-
/// The type of webhook that is being verified
24-
/// </typeparam>
25-
/// <remarks>
26-
/// In several case scenarios, providers of webhooks require a verification
27-
/// of the party to ensure they are the ones who should be receiving the
28-
/// webhooks, and not a malicious party.
29-
/// </remarks>
30-
public interface IWebhookRequestVerifier<TWebhook> {
18+
/// <summary>
19+
/// A service that is used to verify a request of acknowledgement
20+
/// by the sender of a webhook, before the webhook is sent.
21+
/// </summary>
22+
/// <typeparam name="TWebhook">
23+
/// The type of webhook that is being verified
24+
/// </typeparam>
25+
/// <remarks>
26+
/// <para>
27+
/// In several case scenarios, providers of webhooks require a verification
28+
/// of the party to ensure they are the ones who should be receiving the
29+
/// webhooks, and not a malicious party.
30+
/// </para>
31+
/// <para>
32+
/// The process of verification is usually a two-step process, where the
33+
/// request is first validated, and then the instance of the result of the
34+
/// validation is passed back to the verifier to handle the result towards
35+
/// the sender: this mechanism is used to ensure that the verification process
36+
/// is specific for the provider of the webhook, since the different methodologies
37+
/// implemented by various providers.
38+
/// </para>
39+
/// </remarks>
40+
public interface IWebhookRequestVerifier<TWebhook> {
3141
/// <summary>
3242
/// Verifies the request of acknowledgement of a webhook.
3343
/// </summary>
@@ -42,6 +52,20 @@ public interface IWebhookRequestVerifier<TWebhook> {
4252
/// Returns a <see cref="WebhookVerificationResult"/> that indicates the result
4353
/// of the verification operation.
4454
/// </returns>
45-
Task<WebhookVerificationResult> VerifyRequestAsync(HttpRequest httpRequest, CancellationToken cancellationToken = default);
55+
Task<IWebhookVerificationResult> VerifyRequestAsync(HttpRequest httpRequest, CancellationToken cancellationToken = default);
56+
57+
58+
/// <summary>
59+
/// Handles the result of the verification of a webhook request.
60+
/// </summary>
61+
/// <param name="result">The result of the verification that should be handled</param>
62+
/// <param name="httpResponse">The HTTP response used to notify the sender</param>
63+
/// <param name="cancellationToken">
64+
/// A token that can be used to cancel the operation
65+
/// </param>
66+
/// <returns>
67+
/// Returns a <see cref="Task"/> that completes when the result is handled.
68+
/// </returns>
69+
Task HandleResultAsync(IWebhookVerificationResult result, HttpResponse httpResponse, CancellationToken cancellationToken);
4670
}
4771
}

0 commit comments

Comments
 (0)