Tubiteflon

Webhooks

Sometimes the caller is not a person but a vendor: DocuSign Connect posting envelope events to your app, for example. An API token is the wrong credential for that. It belongs to whoever minted it, lives at most 180 days, and the integration dies silently when it expires or that person leaves. A webhook is the credential for a third party: one sender allowed to call one exact path on your app.

Every request to your app still goes through the gateway's auth. A webhook does not open a path to the public. It gives the vendor a way to prove who it is, without a browser and without a person behind it.

Create one

teflon webhook create my-app --name docusign --path /hooks/docusign

The name is letters, digits, and dashes, like docusign-connect, and uppercase is folded to lowercase. The path carries no query string and cannot be under /.teflon/. A missing leading slash is added for you, and pasting the full delivery URL works too; only its path is kept.

create prints four things, once:

OutputExampleWhat it is
Token URLhttps://auth.tf.int.tubi.io/.teflon/auth/webhooks/tokenWhere the vendor trades its credentials for a token
Client ida uuidThe vendor's username
Client secretstarts with tfws_The vendor's password
Deliver-to URLhttps://my-app.tf.int.tubi.io/hooks/docusignThe address the vendor posts events to

Store the secret now. It is never shown again, and list shows nothing about it. If it is lost, rotate mints a new one.

teflon webhook list my-app
teflon webhook rotate my-app docusign
teflon webhook delete my-app docusign

The owner and the app's admins (see Sharing control in Developing your application) can manage webhooks. Allow-list members cannot. A webhook's secret belongs to the app, not to a person.

How the auth works

A webhook uses the OAuth 2.0 client credentials grant (RFC 6749, section 4.4). That is the machine-to-machine flow: no browser, no login page, no person. It is OAuth only, not OpenID Connect, so there is no id token and no user.

The whole exchange has two steps.

  1. The vendor trades its client id and secret for a short-lived token at the token URL.
  2. The vendor sends that token with every delivery, and the proxy checks it before your app sees anything.
vendor                    token URL                    proxy                  your app
  |  client id + secret      |                           |                       |
  |------------------------->|                           |                       |
  |  access_token (15 min)   |                           |                       |
  |<-------------------------|                           |                       |
  |  POST /hooks/docusign + Authorization: Bearer ...    |                       |
  |----------------------------------------------------->|  checks the token     |
  |                                                      |---------------------->|
  |                                                      |  X-Teflon-Webhook     |

Step 1: get a token

The vendor sends a form POST to the token URL. The client id and secret go in HTTP Basic auth or in the form fields; both work, so whichever style the vendor uses is fine.

curl -sS -X POST https://auth.tf.int.tubi.io/.teflon/auth/webhooks/token \
  -u "$CLIENT_ID:$CLIENT_SECRET" \
  -d grant_type=client_credentials
curl -sS -X POST https://auth.tf.int.tubi.io/.teflon/auth/webhooks/token \
  -d grant_type=client_credentials \
  -d client_id="$CLIENT_ID" \
  -d client_secret="$CLIENT_SECRET"

The answer is standard OAuth JSON:

{"access_token": "eyJ...", "token_type": "Bearer", "expires_in": 900}

expires_in is in seconds, so a token lives 15 minutes. Fields the endpoint does not know, such as scope or audience, are ignored, so a vendor that always sends them still works. The response is never cached, and the request body is never logged.

When it fails, the body names the problem:

StatuserrorWhen
401invalid_clientThe id is unknown, the webhook was deleted, the secret is wrong, or the credentials are missing or malformed
400unsupported_grant_typegrant_type is anything but client_credentials
400invalid_requestThe body is not a form
503noneTeflon could not finish the request; retry

The four 401 cases are deliberately identical. Nobody can use the token URL to find out which client ids exist.

The token URL is rate limited per IP address: 100 requests per 5 minutes across everything under /.teflon/auth/. A vendor should keep its token for the 15 minutes and fetch a new one only when it expires or a delivery gets a 401, not before every delivery.

Step 2: deliver with the token

The vendor posts the event with the token in the Authorization header.

curl -sS -X POST https://my-app.tf.int.tubi.io/hooks/docusign \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"event": "envelope-completed"}'

The token is a signed JWT. It says who it is for and what it may do:

ClaimValue
audteflon-webhook
subThe webhook id, which is also the client id
nameThe webhook's name, such as docusign
app_idThe one app the webhook belongs to
pathThe one path the webhook was created with
methodPOST
jtiA unique id for this token, used to revoke it
exp15 minutes after it was minted

It is signed with the same Teflon key as API tokens, but its aud is different, so the two kinds never pass for each other. A webhook token is useless anywhere except the proxy, and the Teflon API refuses it.

The proxy runs these checks, in this order:

CheckIf it fails
The signature, issuer, audience, and expiry are valid401
The token has not been revoked401
app_id is the app this hostname belongs to403
The request method is the token's method403
The request path is exactly the token's path (the query string is ignored)403

A bad or missing token is always a 401, never a redirect to the login page, so a vendor never ends up following a login redirect. A genuine token used on the wrong path or method is a 403. A token minted for /hooks/docusign cannot reach /hooks/other, even on the same app.

The proxy skips the SSO email domain check and the app's allow list for a verified webhook token. There is no person to check, and the token is already tied to one app, one path, and one method.

Revocation

Every token Teflon mints is recorded, and the proxy keeps a list of revoked ones. rotate and delete both put the webhook's live tokens on that list within seconds. The proxy fails closed: if it cannot tell whether a token was revoked, it refuses the token.

What Teflon stores

Teflon stores a SHA-256 hash of the client secret, never the secret itself. The secret is 32 random bytes made by Teflon, so a hash is enough; it cannot be guessed, and you cannot pick your own. It only ever reaches the token URL. It never reaches the proxy or your app. It has no expiry date, so nothing breaks on day 31. The tfws_ prefix is there so a leaked secret is easy to find with a code or secret scanner.

Configuring DocuSign Connect

In DocuSign, open the Connect configuration that publishes to your app and enable OAuth in its security settings. Then fill in four fields from the create output.

DocuSign fieldAPI nameValue from teflon webhook create
URL to publish tourlToPublishToThe deliver-to URL, https://my-app.tf.int.tubi.io/hooks/docusign
Authorization server URLauthorizationServerUrlThe token URL
Client idclientIdThe client id
Client secretclientSecretThe client secret

The last three live under the Connect OAuth configuration in DocuSign's API. Leave scope and any custom parameters empty. Do not turn on DocuSign's HMAC signature option expecting Teflon to check it; see Not supported below.

Any other vendor that supports OAuth client credentials for its outbound webhooks works the same way. Give it the token URL, the client id, the client secret, and the deliver-to URL.

Try it by hand

Before you hand the credentials to a vendor, prove the whole flow from your terminal.

ACCESS_TOKEN=$(curl -sS -X POST https://auth.tf.int.tubi.io/.teflon/auth/webhooks/token \
  -u "$CLIENT_ID:$CLIENT_SECRET" \
  -d grant_type=client_credentials | jq -r .access_token)

curl -i -X POST https://my-app.tf.int.tubi.io/hooks/docusign \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{}'

A response from your app means it works. A 401 from the first command means the credentials are wrong. A 403 from the second means the path or method does not match the webhook.

What your app sees

A webhook delivery arrives with one header instead of the two identity headers:

HeaderValue
X-Teflon-WebhookThe webhook's name, docusign above

There is no X-Auth-Request-Email and no X-Auth-Request-User, because there is no person. An app that serves both people and vendors can tell them apart by which set of headers is present. As with the identity headers, the proxy strips any inbound X-Teflon-Webhook before setting its own, so a user cannot pretend to be a vendor. The Authorization header is removed before forwarding, like on every other request.

What your app has to do

Vendors retry a failed delivery for days, and a slow success is a failure to them. Three rules keep a webhook handler healthy:

  • Deduplicate on the vendor's own event id. An event that was delivered once can arrive again after a retry, and DocuSign in particular resends anything it could not confirm.
  • Answer with a 2xx within a few seconds and do the real work in the background. The gateway cuts off any response slower than 60 seconds (see Timeouts and request limits in Developing your application), and the vendor counts that as a failed delivery.
  • Never redirect. Vendors treat a 3xx as a failure, and the token is pinned to the exact path anyway, so the redirected request would be a 403. Watch for frameworks that redirect /hooks/docusign/ to /hooks/docusign or the other way round; register the exact path the vendor will post to.

Rotating and deleting

rotate and delete both revoke the webhook's live tokens within seconds, so a stolen token dies with the secret it came from. A vendor with the old secret then fails at the token URL until it has the new one, and retries the deliveries that failed in between. When rotating on purpose, have the vendor's settings page open and paste the new secret in as soon as rotate prints it, so that gap stays short. A deleted webhook's name can be reused by a new create.

Not supported

Only OAuth client credentials work today. Vendors that only sign deliveries with an HMAC header (Stripe, GitHub, Slack, Shopify) cannot use a webhook yet. Teflon does not check an HMAC signature header, so turning that option on at the vendor does nothing for you.

The method is always POST, and a webhook covers exactly one path. A vendor that posts to two paths needs two webhooks.

In the console

The app's detail page has a Webhooks card on its Integrations tab with the same controls as the CLI: list, create, rotate, and delete. The client secret appears once, in a panel you can dismiss, right after create or rotate.