Token Refresh Demo

Protected-Content Playback

Demonstrates automatic token refresh for Gcore protected HLS streams. Tokens and the ready-to-play URL are issued by a demo FastEdge serverless app built on a custom Gcore CDN resource. You can deploy the same token-issuing logic in your account via Gcore FastEdge, or implement it on your own backend with any authentication method.
On this demo page tokens are issued for 20 seconds; the TokenRefreshPlugin fetches a new token 10 seconds before expiry and rewrites every hls.js request URL transparently — no buffering interruption.

Protected HLS Stream

VOD content served via Gcore CDN with path-embedded token.

Fetching token…

How it works — hls.js: TokenRefreshPlugin injects a custom hls.js loader that rewrites /{token}/{expires}/ in every segment, playlist and key URL before the XHR is opened. The refresh timer fires 10 s before expiry and updates the shared token state — the loader picks it up on the very next request with zero interruption.

dash.js: For DASH streams the plugin registers a requestInterceptor on the dash.js MediaPlayer instance. The interceptor rewrites the same /{token}/{expires}/ pattern in every segment and manifest request, giving seamless token refresh with no buffering gap. Pass a DASH source with mimeType: "application/dash+xml" and the plugin selects the DASH path automatically.

Safari (native HLS): hls.js runs on Safari 14.5+ (MSE support) so the seamless loader path is used. Older Safari falls back to native <video> HLS; the plugin then reloads the source URL and seeks back to the saved position. For fully seamless refresh on older Safari, register token-refresh-sw.js as a Service Worker — the SW intercepts all CDN fetch requests and rewrites the token even for native media elements.