Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldwight committed Aug 12, 2023
2 parents 90d1b31 + d2a2c6c commit e976f34
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,36 @@ public async Task<IActionResult> GetMessage()
}
```

## Verify Webhook X-Hub-Signature-256 (.NET 7 Minimal API) (Credits @sapharos)
```c#
app.Use((context, next) =>
{
context.Request.EnableBuffering();
return next();
});

// Validation implementation
string stringifiedBody;
string xHubSignature256 = context.Request.Headers["X-Hub-Signature-256"].ToString();
context.Request.Body.Seek(0, SeekOrigin.Begin);
using (var sr = new StreamReader(context.Request.Body))
{
stringifiedBody = await sr.ReadToEndAsync().ConfigureAwait(false);
}
string xHubSignature256Result = FacebookWebhookHelper.CalculateSignature(_config.GetValue<string("Facebook:AppSecret"), stringifiedBody);
if (!String.Equals(xHubSignature256, xHubSignature256Result,StringComparison.InvariantCultureIgnoreCase))
{
return Results.Unauthorized();
}
```

## Error handling
WhatsAppBusinessClient Throws ```WhatsappBusinessCloudAPIException``` It is your role as the developer to catch
the exception and continue processing in your aplication. Snippet below shows how you can catch the WhatsappBusinessCloudAPIException.
the exception and continue processing in your application. Snippet below shows how you can catch the WhatsappBusinessCloudAPIException.

```c#
using WhatsappBusiness.CloudApi.Exceptions; // add this to you class or namespace
using WhatsappBusiness.CloudApi.Exceptions; // add this to your class or namespace
try
{
Expand All @@ -600,11 +624,11 @@ catch (WhatsappBusinessCloudAPIException ex)
```
## Issues

If you will face any issue with the usage of this package please raise one so as we can quickly fix it as soon as possible.
If you will face any issues with the usage of this package please raise one so as we can quickly fix it as soon as possible.

## Contributing

This is an opensource project under ```MIT License``` so any one is welcome to contribute from typo, to source code to documentation.
This is an open-source project under ```MIT License``` so anyone is welcome to contribute from typos, to source code to documentation.

## Credits
1. [Gabriel](https://github.com/gabrieldwight)
Expand Down

0 comments on commit e976f34

Please sign in to comment.