Adding Authentication When Forwarding a Webhook
Authenticate senders and destination services in one webhook relay.
PayloadRelay supports authentication on the two sides of a relay. Inbound authentication controls who can send to the endpoint. Outbound authentication controls how PayloadRelay authenticates with the destination. This guide shows how to configure the two sides.
Purpose#
Use this guide to:
- Protect an endpoint with inbound authentication.
- Configure outbound authentication on a webhook destination.
- Build an authenticated relay between two services.
- Select an authentication type for your use case.
Before you start#
- Make sure that you can edit endpoints and create or edit relay targets.
- Get the credentials of the sending service for the inbound authentication.
- Get the credentials of the destination service for the outbound authentication.
Procedure#
1. Understand the two authentication layers#
Sending Service ──auth──► PayloadRelay Endpoint ──auth──► Destination Service
(inbound) (outbound)- Inbound authentication makes sure that the sender can use the endpoint.
- Outbound authentication authenticates PayloadRelay with the destination.
Each layer is independent. You can use inbound authentication, outbound authentication, or the two together.
2. Configure inbound authentication#
Open the endpoint in Endpoints. Select Security, then select an authentication type:
Use this type for service-to-service communication and an API integration.
- Select
Bearer tokenas the authentication type. - Enter a strong token value, for example, a value from
openssl rand -hex 32. - Save.
The sender must put the token in every request:
curl -X POST https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID \
-H "Authorization: Bearer your-secret-token-here" \
-H "Content-Type: application/json" \
-d '{"event": "order.created", "order_id": "12345"}'If the destination needs a custom header name, use this type.
- Select
API key headeras the authentication type. - Set the header name, for example,
X-Api-Key. - Enter the key value.
- Save.
curl -X POST https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID \
-H "X-Api-Key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{"event": "order.created", "order_id": "12345"}'Use this type for a simple integration and a tool that supports HTTP Basic authentication.
- Select
Basicas the authentication type. - Enter the username and the password.
- Save.
curl -X POST https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID \
-u "username:password" \
-H "Content-Type: application/json" \
-d '{"event": "order.created", "order_id": "12345"}'A request with no valid credentials receives a 401 response. It appears as Auth Failed (AUTH_FAILED) in Activity.
3. Configure outbound authentication#
Open the endpoint in Endpoints. Select Outputs, then configure the authentication on the destination that uses the webhook target:
Bearer token (outbound)
- Edit the endpoint and select the
Outputstab. - Expand the configuration of the webhook destination.
- Select
Beareras the authentication type. - Enter the Bearer token that the destination expects.
- Save.
PayloadRelay adds Authorization: Bearer <token> to every forwarded request.
API key header (outbound)
- Edit the endpoint, and expand the webhook destination configuration in
Outputs. - Select
API keyas the authentication type. - Set the header name that the destination expects, for example,
X-Api-Key. - Enter the key value.
- Save.
Basic authentication (outbound)
- Edit the endpoint, and expand the webhook destination configuration in
Outputs. - Select
Basicas the authentication type. - Enter the username and the password that the destination expects.
- Save.
Custom headers (outbound)
For a destination that needs more headers than the authentication headers:
- Edit the endpoint, and expand the webhook destination configuration in
Outputs. - Add a maximum of 25 custom headers. Mark a credential-like header as sensitive. PayloadRelay encrypts these values, and it does not show them after you save. A header value supports a template variable such as
{{originating_ip}}and{{uuid}}. - Save.
For example, a destination needs an API key and a tenant ID header:
- Auth type:
API keywith headerX-Api-Key - Custom header:
X-Tenant-Id: acme-corp
Header forwarding
You can forward a header from the incoming request to the webhook target:
Forward all incoming headers: PayloadRelay forwards the permitted headers from the incoming request. PayloadRelay always removes the restricted headers and the endpoint-specific credential headers.Forward specific headers: PayloadRelay forwards the header names that you give. If a header is not in the incoming request, PayloadRelay ignores it.
A custom header has priority over a forwarded header with the same name.
PayloadRelay always removes these restricted headers. They are connection-specific, or PayloadRelay sets them for the outbound request, or they are security-sensitive:
Host, Connection, Content-Length, Content-Type, Transfer-Encoding, Upgrade,
Proxy-Authorization, Proxy-Connection, TE, Trailer, Expect, Keep-Alive,
HTTP2-Settings, Authorization, Cookie, Set-Cookie, X-PayloadRelay-Forward-Chain,
X-PayloadRelay-Delivery-Id, X-PayloadRelay-Event-Id, X-PayloadRelay-Attempt
PayloadRelay also removes the endpoint required-header names, the inbound API key header, the inbound HMAC signature header, and the Slack timestamp header that the Slack HMAC preset uses. A template cannot use these dynamic credential headers and validation headers. The specific-header list cannot send them. If the destination needs its own credential, configure separate outbound authentication or a sensitive custom header on the destination.
4. HTTPS enforcement#
For an outbound webhook destination, enable Enforce HTTPS to reject a target URL that does not use
HTTPS. An HTTPS connection always uses the normal TLS certificate validation. If you disable this
control, PayloadRelay still rejects an invalid certificate.
5. End-to-end example: secure webhook relay#
In this example, Service A sends order events to Service B through PayloadRelay. The two sides use authentication.
Step 1: Create the webhook target for Service B
- Open
Relay targets, selectAdd target, then selectWebhook URL. - Enter the URL of Service B:
https://api.service-b.com/webhooks/orders - Save.
Step 2: Create the endpoint
- Open
Endpointsand selectCreate endpoint. - Set the method to
POSTand the payload format toJSON. - In
Security, set the authentication type toBearer tokenwith a token for Service A. - In
Outputs, attach the Service B webhook target. - Configure the outbound authentication with the type
Bearerand the token of Service B. - Enable
Enforce HTTPS. - Save the endpoint. Give the endpoint URL and the token to the Service A team.
Step 3: Service A sends events
# Service A sends to PayloadRelay
curl -X POST https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID \
-H "Authorization: Bearer service-a-token" \
-H "Content-Type: application/json" \
-d '{
"event": "order.created",
"order_id": "ORD-98765",
"customer": "[email protected]",
"total": 149.99,
"currency": "USD"
}'What happens:
- PayloadRelay examines the Bearer token of Service A for the inbound authentication.
- PayloadRelay accepts the request for delivery.
- PayloadRelay sends the payload to
https://api.service-b.com/webhooks/orderswith the Bearer token of Service B for the outbound authentication. - Activity records the inbound acceptance and the outbound delivery.
6. Compare authentication types#
| Authentication type | Use | Header sent |
|---|---|---|
| Bearer token | A service API and automation | Authorization: Bearer <token> |
| API key header | A custom header name is necessary | <Header-Name>: <key> |
| Basic authentication | A legacy system, a simple tool | Authorization: Basic <base64> |
| None | A public endpoint, a test | No authentication header |
7. Rotate credentials#
Use this procedure to change the authentication credentials:
- Update the destination to accept the old credentials and the new credentials.
- Update the PayloadRelay endpoint security configuration or the webhook destination with the new credential.
- Send a representative request through the saved endpoint. Make sure that the destination receives it.
- Remove the old credential from the destination.
This sequence prevents a delivery failure during the change.
Expected result#
- A request with no authentication returns
401withAUTH_FAILED. - A request with valid authentication returns
202 Acceptedafter PayloadRelay accepts the event. A temporary failure can return503withRetry-After. Wait for the given time, then send the request again with the same event key. For the destination delivery outcome, follow Activity. - A forwarded request contains the configured outbound authentication headers.
- An inbound authentication failure appears as
AUTH_FAILED. An outbound credential problem appears in the destination delivery outcome and the error details.
Common issues#
AUTH_FAILEDon the inbound side: make sure that the authentication type and the credential values agree with the endpoint configuration.- An outbound delivery failure: make sure that the webhook destination uses the authentication type and the credentials that the destination needs.
- PayloadRelay blocks a target that does not use HTTPS: use HTTPS, or disable
Enforce HTTPSfor that destination. With this control disabled, PayloadRelay still rejects a self-signed certificate and a different invalid TLS certificate. Correct the certificate. - A custom header conflict: a custom header cannot use the same name as an authentication header. For example, you cannot add a custom
Authorizationheader when Bearer authentication is enabled.