A minimal Go server for authenticating webhook requests using bearer tokens mapped to stream keys via environment variables.
This server is built to be used together with github.com/glimesh/broadcast-box.
This server allows asynchronous definition of a secret stream key and a string representing the name of the stream for your watchers. This enables private streams without the need to expose the key to allow streaming (WHIP).
Example:
Suppose you want to allow a streamer to ingest using a secret key, but let viewers watch using a public stream name:
WEBHOOK_ENABLED_STREAMKEYS="supersecretkey:myprivatestream"
- The streamer uses
supersecretkeyto start streaming (WHIP connect). - Viewers/watchers use
myprivatestreamto watch (WHEP connect), without ever seeing the secret key.
- Accepts POST requests with a JSON payload
- Authenticates using bearer tokens
- Returns the mapped stream key if authentication succeeds
- Logs invalid attempts
Set WEBHOOK_ENABLED_STREAMKEYS to a comma-separated list of bearerToken:streamKey pairs. Example:
WEBHOOK_ENABLED_STREAMKEYS="token1:streamkey1,token2:streamkey2"
version: '3'
services:
broadcastbox:
image: "seaduboi/broadcast-box"
environment:
# your custom settings for
- DISABLE_STATUS=true
- WEBHOOK_URL=http://webhookserver:8000
ports:
# adjust according your needs
- "8080:8080"
- "18084:18084/udp"
restart: always
links:
- "webhookserver"
webhookserver:
image: "ghcr.io/chrisingenhaag/broadcastbox-webhookserver:1.1.4"
environment:
- WEBHOOK_ENABLED_STREAMKEYS=mysecretstreamkey:thepublicstreamname
restart: always- Clone the repository:
git clone https://github.com/chrisingenhaag/broadcastbox-webhookserver.git cd broadcastbox-webhookserver - Set the environment variable:
export WEBHOOK_ENABLED_STREAMKEYS="token1:streamkey1,token2:streamkey2"
- Start the server:
The server listens on port 8000 by default.
go run main.go
curl -X POST http://localhost:8000/ \
-H "Content-Type: application/json" \
-d '{
"action": "test",
"ip": "127.0.0.1",
"bearerToken": "token1",
"queryParams": {},
"userAgent": "curl"
}'
{"streamKey":"streamkey1"}
{"streamKey":""}
- Build the Docker image:
docker build -t broadcastbox-webhookserver . - Run the container:
docker run -p 8000:8000 -e WEBHOOK_ENABLED_STREAMKEYS="token1:streamkey1,token2:streamkey2" broadcastbox-webhookserver
Run tests with:
go testApache License 2.0