sdk-csharp icon indicating copy to clipboard operation
sdk-csharp copied to clipboard

Web hook validation in 2.x+ not present anymore?

Open sandromastronardi opened this issue 2 years ago • 4 comments

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

sandromastronardi avatar Oct 18 '22 13:10 sandromastronardi