Check Authorization Header

For n8n, this workflow secures a public webhook by validating Bearer token authentication and ensuring all required fields are present in incoming requests. It provides clear JSON responses for successful requests (200 OK) and error handling (400 Bad Request for missing fields, 401 Unauthorized for invalid tokens), enhancing the reliability and security of API integrations.

7/8/2025
16 nodes
Complex
webhookcomplexrespondtowebhooksticky notenoopadvancedlogicconditionalintegrationapi
Categories:
Complex WorkflowWebhook Triggered
Integrations:
RespondToWebhookSticky NoteNoOp

Target Audience

Target Audience

- Developers: Looking to implement secure webhooks with authentication in their applications.
- API Integrators: Need a reliable method to validate incoming requests and ensure data integrity.
- Businesses: Want to protect sensitive endpoints and ensure only authorized access to their services.
- Technical Teams: Seeking to streamline error handling and response management in webhook integrations.

Problem Solved

Problem Solved

- Unauthorized Access: Prevent unauthorized users from accessing your webhook by requiring a valid Bearer token.
- Missing Fields: Ensure that all required data fields are present in incoming requests, reducing errors and improving data quality.
- Standardized Responses: Provide consistent JSON error messages for better client-side handling of API responses.

Workflow Steps

Workflow Steps

1. Webhook Node: Listens for incoming POST requests on the /secure-webhook endpoint.
2. Configuration Node: Sets the expected Bearer token and any required fields for validation.
3. Check Authorization Header: Validates the Authorization header against the configured token. If invalid, it triggers a 401 Unauthorized response.
4. Has Required Fields?: Validates that all required fields specified in the configuration are present in the request body. If any field is missing, it triggers a 400 Bad Request response.
5. Check Valid Request: If all validations pass, it proceeds to the next workflow nodes for further processing.
6. Create Response Node: Constructs a success message to be returned to the client.
7. 200 OK: Sends back a successful response with the constructed message.

Customization Guide

Customization Guide

- Bearer Token: Update the config.bearerToken in the Configuration node to set your own authentication token.
- Required Fields: Modify config.requiredFields to include keys for any fields you want to validate in the incoming request body. The values can be anything, as only keys are checked.
- Add Workflow Logic: Replace the Add workflow nodes here node with your own processing logic to handle valid requests as needed.
- Response Customization: Edit the Create Response node to customize the success message returned to the client.