Cloudflare Access Setup
Connect SoundLeaf to your Audiobookshelf server behind Cloudflare Zero Trust
If you’re running Audiobookshelf behind a Cloudflare Tunnel with Zero Trust protection, you’ll need to configure custom headers in SoundLeaf to authenticate.
Why Custom Headers?
Cloudflare Access adds an authentication layer before your Audiobookshelf server. When you access your server through a browser, Cloudflare prompts you to log in (via email OTP, Google, etc.). But apps can’t do that browser-based flow.
Instead, apps use Service Tokens - a Client ID and Secret that bypass the Cloudflare login and go straight to your server. You still need your Audiobookshelf username and password after that.
Step 1: Create a Service Token
- Go to Cloudflare Zero Trust Dashboard
- Navigate to Access → Service Auth → Service Tokens
- Click Create Service Token
- Name it something like “SoundLeaf iOS”
- Copy both values:
CF-Access-Client-IdCF-Access-Client-Secret
Important: The secret is only shown once. Save it somewhere secure.
Step 2: Add a Service Auth Policy
This is the step most people miss. Your service token needs a Service Auth policy, not just an Allow policy.
- Go to Access → Applications
- Select your Audiobookshelf application
- Go to Policies tab
- Click Add a policy
- Set:
- Policy name: “Service Token Access”
- Action: Service Auth (not Allow!)
- Include: Service Token → select the token you created
Step 3: Configure SoundLeaf
- Open SoundLeaf
- On the login screen, tap Headers
- Tap Add from template and select
CF-Access-Client-Id - Paste your Client ID value
- Tap Add from template again and select
CF-Access-Client-Secret - Paste your Client Secret value
- Make sure both headers are enabled (toggle on)
- Tap Done
Now enter your server URL and Audiobookshelf credentials as usual.
Troubleshooting
”Login failed” or “Connection failed”
- Double-check your Client ID and Secret are correct (no extra spaces)
- Verify the headers are enabled (green toggle)
- Ensure you created a Service Auth policy, not just an Allow policy
Images or playback not working
SoundLeaf sends these headers with every request, including images and audio streams. If you’re having issues:
- Check your Cloudflare session duration isn’t too short
- Verify the service token policy applies to the entire application, not just specific paths
Still stuck?
Check the Cloudflare Zero Trust docs for more details on service tokens.