Signing requests | laravel-webhook-server-rust | Spatie       

 SPATIE  

laravel-webhook-server-rust
===========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-webhook-server-rust](https://spatie.be/docs/laravel-webhook-server-rust/v1)  Signing requests

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-webhook-server-rust/v1) 

  Signing requests    
- [ Introduction ](https://spatie.be/docs/laravel-webhook-server-rust/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-webhook-server-rust/v1/installation-and-setup)
- [ Sending webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/sending-webhooks)
- [ Signing requests ](https://spatie.be/docs/laravel-webhook-server-rust/v1/signing-requests)
- [ Retrying failed webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/retrying-failed-webhooks)
- [ Transport options ](https://spatie.be/docs/laravel-webhook-server-rust/v1/transport-options)
- [ Events ](https://spatie.be/docs/laravel-webhook-server-rust/v1/events)
- [ Testing webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/testing-webhooks)
- [ Upgrading ](https://spatie.be/docs/laravel-webhook-server-rust/v1/upgrading)
- [ Testing ](https://spatie.be/docs/laravel-webhook-server-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-webhook-server-rust/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-webhook-server-rust/v1/support-us)

 Signing requests
================

###  On this page 

1. [ Change or disable the signature header ](#content-change-or-disable-the-signature-header)
2. [ Custom signers ](#content-custom-signers)
3. [ Customize body serialization ](#content-customize-body-serialization)

The default signer calculates HMAC-SHA256 over the exact prepared body, encoded as lowercase hexadecimal in the `Signature` header. Share a secret with the receiver and set it using `use_secret`. Receivers should verify against the raw received body using a constant-time MAC verification function.

Raw bytes are unchanged; JSON is encoded before signing. The URL, headers, delivery ID and timestamp header are not authenticated by the default signer. GET sends query parameters and signs the payload's JSON representation instead.

Change or disable the signature header
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Set `Config.signer` to `Arc::new(DefaultSigner { header_name: "X-Signature".into() })`. Use `do_not_sign()` to omit the package signature without supplying a secret. An explicitly supplied signature header is then left untouched.

Custom signers
--------------------------------------------------------------------------------------------------

Implement `Signer` and select it with `Config.signer` or per-call `sign_using`:

```
use spatie_laravel_webhook_server::{DefaultSigner, Error, Signer};

#[derive(Debug)]
struct UrlAwareSigner;

impl Signer for UrlAwareSigner {
    fn signature_header_name(&self) -> &str { "X-Custom-Signature" }

    fn calculate_signature(&self, url: &str, body: &[u8], secret: &[u8]) -> Result<String, Error> {
        let mut message = url.as_bytes().to_vec();
        message.push(b'\n');
        message.extend_from_slice(body);
        DefaultSigner::default().calculate_signature(url, &message, secret)
    }
}
```

The signer sees already-serialized bytes. Do not serialize them again. The secret is used only before dispatch and is absent from `PreparedWebhook` and delivery events. Payloads, headers and metadata may still contain application secrets; protect access to queues and event storage.

Customize body serialization
--------------------------------------------------------------------------------------------------------------------------------------------

Implement `BodySerializer::serialize(&Payload) -> Result<Vec<u8>, Error>` and assign `Config.serializer`. For a per-call encoding, supply pre-encoded bytes through `send_raw_body`. Serialization runs before signing and dispatch. Retries never re-encode the payload.

Laravel HTTP client hooks apply to these requests. A hook that changes signed bytes must update the signature too.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
