π How to Secure Webhooks in n8n with Bearer Token & Field Validation
In this guide, Iβll show you how to build a secure n8n webhook that uses a Bearer Token for authentication and dynamic field validation to make sure the incoming request has everything you need β no code-heavy setup required.
β‘ Why Secure Webhooks in n8n?
By default, n8n webhooks are public. Thatβs great for ease of use, but dangerous if you're expecting sensitive or structured data from clients, forms, or APIs.
With this workflow, you get:
- β Bearer Token authentication
- β Dynamic validation of required fields
- β
Clean JSON responses for
200
,400
, and401
- β A modular setup you can reuse and extend
Perfect for form submissions, private APIs, or automation endpoints.
π§ How the Secure Webhook Workflow Works
Hereβs a quick breakdown of whatβs inside:
1. Webhook
Node
Receives POST requests from external services.
2. Configuration
Node
Set:
config.bearerToken
β Your secret tokenconfig.requiredFields
β Add a key for each required field (e.g.message
,email
)
3. Auth Check π
Validates the Authorization
header using Bearer token logic.
4. Field Check π§ͺ
Uses a Code node to loop through config.requiredFields
and compare with the request body.
5. Error Handling π
Returns:
401
if the token is missing or wrong400
if required fields are missing
6. Success Response β
Returns a 200 OK
with your custom message.
π How to Set It Up
- Download the workflow below and import it into your n8n instance.
- Open the
Configuration
node:- Add your Bearer token.
- Define the required fields.
- Customize the success response if needed.
- Plug in your own logic after the validation step.
It takes 2 minutes to make your webhook production-ready.
πΎ Download the Workflow ($2)
Want to save time and grab a clean, production-ready template?
Comes with:
- Full validation logic
- Config instructions
- Modular and ready to expand
π Like This? Support My Work
I build helpful tools and templates for the n8n community.
- π‘ More n8n templates on my site
- π§ββοΈ Verified n8n creator profile
Thanks for reading! Now go secure those webhooks πͺ