🍅
bl.cdm
  • 🙋Hey there! I'm Steven 🚀
  • 🐛Using Cloudflare Access Service Tokens with a Single JSON Header
  • 📬How to remove your old iCloud email (not alias)
  • 📺YouTube subscriptions export / import
  • 🔍Cloud Run Deployment Preview Github Actions workflows
  • 🪞Static website deployment preview with S3 and CloudFront
  • 🐋Allow Docker Remote API access over Tailscale network
  • 📟I built a cheapo arm server using an old TV box
  • 🪦I built a cheapo NAS
  • 🤖How I monitor my Windows machines using Grafana
  • 🐘Connect to PostgreSQL 15 database on Amazon Linux 1
  • 🔮Circle CI - AWS Assume Role Orb
  • 🐳Deploy JupyterHub with GitLab Authenticator on Docker
Powered by GitBook
On this page
  • TL;DR
  • Background
  • Problem
  • Solution

Was this helpful?

Using Cloudflare Access Service Tokens with a Single JSON Header

PreviousHey there! I'm Steven 🚀NextHow to remove your old iCloud email (not alias)

Last updated 25 days ago

Was this helpful?

TL;DR

  • Cloudflare Access supports single-header service token authentication using JSON

  • The JSON keys must be lowercase: cf-access-client-id, cf-access-client-secret

  • Set read_service_tokens_from_header to your custom header name

Background

Cloudflare Access supports authenticating requests to protected resources using service tokens, typically via two headers:

CF-Access-Client-Id: <client_id>
CF-Access-Client-Secret: <client_secret>

However, for some use cases—especially API calls or automation, my case is MCP workers with Zero Trust protected—you may want to consolidate authentication into a single header. While mentions this, one critical detail is not clearly documented: the required lowercase key names in the JSON payload.

Funny enough, even their sample cURL command is in the incorrect format — wrong casing and use of underscores. 🤦🏻‍♂️

Problem

Attempting to use a single header like this:

curl -H 'Authorization: {"CF-Access-Client-Id": "abc", "CF-Access-Client-Secret": "def"}' \
     https://example.workers.dev

…results in a 403 Forbidden, even if:

  • The token values are correct

  • The header is well-formed

  • Your Cloudflare Access app is configured with read_service_tokens_from_header

Solution

Use lowercase keys in the JSON string:

curl -H 'Authorization: {"cf-access-client-id": "abc", "cf-access-client-secret": "def"}' \
     https://example.workers.dev

This works only if:

  • The read_service_tokens_from_header field is set (via Terraform, API)

  • The JSON is valid and properly escaped

  • The header name matches exactly

🐛
Cloudflare’s documentation