What this thread does
Our recommendation: send APNs requests from a deployed Cloudflare Worker, sign an ES256 provider token with Web Crypto, and reuse it within Apple's 20–60 minute refresh window (runtime report, Apple token guidance).
Do first: make the initial APNs request from a deployed Worker; Aleksandr Bagatka's APNs README reports that local wrangler dev lacks the required transport.
Send one alert
1. Use https://api.sandbox.push.apple.com for development tokens or https://api.push.apple.com for production tokens. Apple requires HTTP/2 with TLS 1.2 or later. POST to /3/device/<DEVICE_TOKEN> (Apple, request construction). 2. Decode the Base64 contents between the .p8 PEM markers into PKCS8 DER bytes; do not pass PEM text directly to importKey. Bagatka's key importer uses a P-256 PKCS8 private key, imported for signing. Cloudflare documents ECDSA import and signing in its Web Crypto API. 3. Set the JWT header to {"alg":"ES256","kid":"<KEY_ID>"} and claims to {"iss":"<TEAM_ID>","iat":<CURRENT_UNIX_SECONDS>} (Apple's field definitions). Encode the header and claims as Base64URL, join with a period, sign those bytes, then append the Base64URL signature. Bagatka's signer uses the 64-byte ECDSA r‖s signature.
Our recommendation: use this adaptation of the linked importer and signer for the cryptographic calls; pkcs8Der and unsignedJwtBytes are prepared inputs:
const key = await crypto.subtle.importKey(
"pkcs8", pkcs8Der, { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]
);
const signature = await crypto.subtle.sign(
{ name: "ECDSA", hash: "SHA-256" }, key, unsignedJwtBytes
);
Issue the request inside a Worker handler, as Cloudflare's Fetch documentation requires. This sketch adapts Apple's alert request; replace the placeholders with your own values:
const response = await fetch("https://api.sandbox.push.apple.com/3/device/<DEVICE_TOKEN>", {
method: "POST",
headers: {
authorization: "bearer <SIGNED_PROVIDER_JWT>",
"apns-topic": "<APP_BUNDLE_ID>",
"apns-push-type": "alert"
},
body: JSON.stringify({ aps: { alert: "Example notification" } })
});
For an ordinary alert, the topic is the app bundle ID and push type is alert. Apple's table requires apns-push-type on watchOS 6+ and recommends it on iOS, iPadOS, macOS and tvOS; its accompanying guidance says to send it with each push. Other types can require topic suffixes (Apple headers). Check the response: 200 has an empty body; failures contain JSON reason values (Apple responses). A successful request does not guarantee device presentation: Apple describes delivery as best effort in its request guide.
What HTTP/2 support means here
Bagatka's README says “HTTP/2 is the host's.” It reports APNs sandbox requests through Effect's FetchHttpClient on deployed Workers; local workerd under wrangler dev cannot reach APNs through that transport. It names no Wrangler or workerd build for the comparison. Cloudflare's protocol reference documents outbound HTTP/HTTPS through fetch; its Fetch API exposes no HTTP-version selector or HTTP/2 connection-pool controls. Availability of fetch alone does not establish local HTTP/2 support.
Diagnostic: TooManyProviderTokenUpdates / InvalidProviderToken
| Symptom | Source's explanation and action |
|---|---|
429 TooManyProviderTokenUpdates | Apple says the provider token changes too often. Reuse it: refresh no more often than every 20 minutes and within 60 minutes. The frequency restriction concerns new tokens on the same connection. |
403 InvalidProviderToken | Apple says the token is invalid or its signature cannot be validated. Our recommendation: check the ES256 header, signing key, Key ID and Team ID against Apple's token guide. Bagatka identifies revoked keys and wrong key/team IDs as credential failures; successful key import alone cannot establish APNs acceptance. |
403 ExpiredProviderToken | Apple says the token is stale. Generate a current token; an iat more than one hour old is rejected. |
Sources: Apple response reasons, Apple token rules, Bagatka's credential handling. These are provider tokens, not device tokens. Bagatka describes one cached token for 50 minutes, shared by concurrent sends. Our recommendation: follow that documented interval rather than signing on every send; the README does not establish coordination across separate Worker isolates.
Availability and evidence
Bagatka's October 24 commit records the runtime comparison; npm's package metadata dates published @bagatka/apns 0.1.0 to October 25, 2026. This helper release does not establish a Cloudflare runtime fix. The report identifies no released workerd HTTP/2 fix or proposed PR. Apple documents the token errors as API behavior rather than a version-specific regression.
Dates and source scope: checked 2026-11-06. Recent independent evidence: Bagatka's October 24 commit and October 25 package/README, one project independent of Apple and Cloudflare. Older stable official references: Cloudflare Fetch (July 5), Web Crypto (September 30) and Protocols (October 13, 2026); Apple's linked APNs pages are undated stable references, not recent release evidence.
Limits
The deployed-versus-local comparison comes from one independent project and identifies no Worker compatibility date. This covers ordinary token-authenticated alerts, not certificate authentication, Live Activity payloads, delivery guarantees, notification permission UX or a distributed token-cache design.
Not for: Expo release-build push delivery troubleshooting; see expo-push-notifications-not-arriving-release-build-checklist.
Started from a post by @Aleksandr Bagatka (bagatka), packaged by the editor. Original post