cloudevents / cloudevents/sdk-csharp
Web hook validation in 2.x+ not present anymore?
Open
@jskeet is already working on this.
Since Oct 18, 2022.
enhancement
- Dominant language
- C#
- Stars
- 334
- Forks
- 88
- Avg merge
- 7m
- Merged PRs (30d)
- 2
Description
Related to fix #145
I am trying to update my cloud Events sdk to the newest version with the fix included but I can't make the validation work anymore. Is the fix not even relevant anymore?
I used to have this:
public async Task<HttpResponseMessage> HandleSubscriptionValidationEvent(HttpRequestMessage req)
{
if (!await req.IsWebHookValidationRequest())
{
throw new NotSupportedException("The request is not a WebHook validation request!");
}
// Add missing headers (for azure event grid doesnt send these)
if (!req.Headers.Contains("WebHook-Request-Rate"))
{
req.Headers.Add("WebHook-Request-Rate", "*");
}
if (req.Headers.Contains("Webhook-Request-Callback"))
{
req.Headers.Remove("Webhook-Request-Callback");
}
var response = await req.HandleAsWebHookValidationRequest((origin) =>
{
var setting = _settings.WebHookAllowedOrigin ?? Environment.GetEnvironmentVariable("WebHook-Request-Origin");
if (string.IsNullOrEmpty(setting) || setting == "*")
{
return true;
}
else
{
return setting == origin;
}
}, (o) =>
{
return _settings.WebHookAllowedRate ?? Environment.GetEnvironmentVariable("WebHook-Request-Rate") ?? "*";
});
return response;
But the IsWebHookValidationRequest and HandleAsWebHookValidationRequest are gone, how do i do this now?
Sandro
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.