Signed Playback
Signed playback means a video can only be watched with a short-lived token created by your Craft site. Without a valid token, Mux refuses to serve the video, its thumbnails, storyboards, captions and downloads.
This page explains how signed playback works and how to use it from Twig and GraphQL. For copy-and-paste reference, see Player Rendering, GraphQL, Element Properties and Settings.
Available from 2.8.0
Token claims, URL helpers, GraphQL tokens, token lifetime settings and playback restrictions described here require Mux for Craft 2.8.0 or later.
Quick start
- Create a signing key. Go to Mux → Signed Keys and create one. The plugin signs every token with it.
- Upload videos as signed. Set Mux → Settings → Secure Playback to Secure. New uploads get a
signedplayback ID. - Render with the helpers. In Twig, use
getPlaybackToken()or theget…Url()helpers. In GraphQL, use thetokenor…Urlfields onplayback_ids. - Headless only: enable Mux → Generate signed playback tokens and URLs on the GraphQL schema your server uses.
- Optional: set a Default Playback Restriction ID to limit which websites can play your videos.
{% set video = entry.video.one() %}
<mux-player
playback-id="{{ video.getPlaybackId() }}"
playback-token="{{ video.getPlaybackToken('v') }}"
thumbnail-token="{{ video.getPlaybackToken('t') }}"
storyboard-token="{{ video.getPlaybackToken('s') }}">
</mux-player>For a public video, getPlaybackToken() returns null, the token attributes are empty and the player plays normally. The same template therefore works for both kinds of video.
Public and signed playback IDs
Mux doesn't play an asset directly. It plays a playback ID that points to the asset, and each playback ID has a policy:
| Policy | Who can watch | URLs need a token |
|---|---|---|
public | Anyone who has the playback ID | No |
signed | Anyone with a valid token for that ID | Yes |
An asset can have both
Because the policy belongs to the playback ID, one asset can have a public and a signed playback ID. Mux creates both when an asset is created with "playback_policy": ["public", "signed"], or when a second ID is added later in the Mux dashboard or API.
The plugin creates one playback ID per upload. Its policy comes from the Secure Playback setting or the upload's override. An asset only has both if a second ID was added in Mux and then synced into Craft.
A public ID unlocks the whole video
Every playback ID gives full access to the asset: stream, thumbnails, storyboards, captions and MP4s. If an asset has a signed ID and a public ID, anyone who learns the public ID can watch everything without a token. It is effectively public.
Good reasons to have both:
- Moving from public to signed: add a signed ID, switch your site to it, then delete the public ID. Deleting it immediately breaks every old public link.
- Revoking a leaked link: delete the leaked ID and create a new one, without re-uploading.
- Different audiences: e.g. a public ID for an internal tool, and a signed, restricted ID for the public site.
A "public preview" of a signed video is not a good reason: the public ID would expose the full video. Use a signed thumbnail or GIF token instead.
Choosing a playback ID
When there is only one playback ID, there is nothing to choose. When there are two:
- Twig: every helper takes an optional
policyargument ('public'or'signed'). Without it, the first playback ID is used, as in earlier versions. - GraphQL: each item in
playback_idshas its ownpolicyand its own tokens and URLs, so your frontend can choose. Useplayback_ids(policy: "signed")to get only one kind.
Token types
A token is only valid for one kind of request. Ask for the type that matches what you're loading:
| Type | Name | Used for | <mux-player> attribute |
|---|---|---|---|
v | video | HLS stream, captions/subtitles (.vtt), MP4/M4A downloads | playback-token |
t | thumbnail | Still images (thumbnail.jpg/png/webp), the player poster | thumbnail-token |
g | gif | Animated previews (animated.gif/webp) | — |
s | storyboard | Timeline hover previews (storyboard.vtt/json/jpg/webp) | storyboard-token |
GraphQL also accepts the long names (video, thumbnail, gif, storyboard).
A thumbnail token can't load the stream, and a video token can't load a thumbnail: Mux answers 403.
Modifiers
Mux lets you change what a URL returns with modifiers, e.g. a thumbnail's width or a stream's max_resolution.
- Public playback ID: modifiers go in the URL's query string, e.g.
thumbnail.jpg?width=640&time=2. - Signed playback ID: modifiers must be inside the token. The URL carries only
?token=…. Mux ignores any other query parameters on a signed URL, so a viewer can't change them.
You don't need to remember which is which. Pass modifiers to the plugin's helpers, and they end up in the right place for the playback ID's policy.
| Token type | Modifiers |
|---|---|
v video | max_resolution, min_resolution (e.g. 720p), rendition_order (desc), redundant_streams, roku_trick_play, default_subtitles_lang, asset_start_time, asset_end_time, program_start_time, program_end_time |
t thumbnail | time (seconds), width, height, fit_mode (preserve, stretch, crop, smartcrop, pad), rotate (90/180/270), flip_v, flip_h |
g gif | start, end (max 10 seconds long), width, height (max 640), fps (max 30) |
s storyboard | none |
| all types | playback_restriction_id, see Playback restrictions |
A modifier that doesn't belong to the token type is dropped. For example, fit_mode passed for a GIF is ignored rather than sent to Mux.
{# Same call for public and signed videos #}
<img src="{{ video.getThumbnailUrl({width: 640, height: 360, fit_mode: 'smartcrop', time: 2}) }}">- Public ID:
https://image.mux.com/{id}/thumbnail.webp?width=640&height=360&fit_mode=smartcrop&time=2 - Signed ID:
https://image.mux.com/{id}/thumbnail.webp?token=eyJ…(the four modifiers are inside the token)
Token lifetime
Every token has an expiry time. The plugin controls it with three settings in config/mux.php:
| Setting | Default | Meaning |
|---|---|---|
signedTokenLifetime | 86400 (24 hours) | How long a token is valid when you don't ask for a lifetime |
maxSignedTokenLifetime | 31536000 (365 days) | The longest lifetime anyone can request. Larger requests are reduced to this. |
signedTokenWindow | 3600 (1 hour) | Rotation window: see below |
Request a different lifetime per token with expiresIn (seconds):
{{ video.getPlaybackToken('v', {}, 3600) }} {# at least 1 hour #}
{{ video.getThumbnailUrl({width: 640}, 'jpg', 604800) }} {# at least 7 days #}playback_ids {
token(type: "v", expiresIn: 3600)
thumbnailUrl(width: 640, expiresIn: 604800)
}Rotation window
The expiry is rounded up to the next full window (hour, by default). That gives you two guarantees:
- Every token is valid for at least the lifetime you asked for, and at most one window longer. With the defaults, between 24 and 25 hours.
- The same request returns the same token for up to one window. Pages, GraphQL responses and CDN caches don't change on every request, so caches keep working.
Caching pages that contain tokens
A cached page keeps serving the tokens it was rendered with, so the cache must expire before those tokens do.
| Cache | What the plugin does | What you do |
|---|---|---|
| Craft GraphQL response cache | Expires automatically when the window rotates | Nothing |
Twig {% cache %} blocks | Expire automatically when the window rotates | Nothing |
| Your own caches (SSR render cache, CDN, static build) | Can't see them | Keep their lifetime shorter than the token lifetime. With the 24-hour default, a 1-hour CDN cache is safe. A 1-week static build needs expiresIn of at least a week. |
Playback restrictions
A token stops a link from working forever. A playback restriction stops it from working anywhere else: Mux only serves the video to the domains you allow.
- Create restrictions under Mux → Playback Restrictions, then make one the default (tick Default on the restrictions page, or use the Default Playback Restriction ID setting, ideally via an env var).
- The plugin adds the default to every signed token, in Twig, GraphQL and the CP. Pass
playback_restriction_idto override it for one token, or""to leave it out. - Restrictions only work for signed playback IDs, and nothing needs to be set at upload.
- Before 2.8.0, restrictions were never added to tokens, so they were never enforced.
Playback Restrictions covers setup, Twig and GraphQL usage, and troubleshooting in full.
Headless and GraphQL
Schema permission
Tokens and signed URLs are only returned to schemas with the Mux → Generate signed playback tokens and URLs permission (muxSignedPlayback:read). Enable it in GraphQL → Schemas on the schema your server-side renderer uses.
| Schema has the permission | Signed playback ID | Public playback ID |
|---|---|---|
| Yes | token and URL fields filled in | token is null, URL fields filled in |
| No | token and URL fields are null | token is null, URL fields filled in |
Only enable it on private schemas
Anyone who can use the schema can create tokens for every signed video the schema can query. Never enable it on the public schema. Keep the schema's access token on your server.
The CP's GraphiQL Full Schema includes the permission, so it's handy for testing.
Which query shape to use
Recommended for production: one list, branch on policy.
fragment MuxVideo on MuxAssetInterface {
playback_ids {
id
policy
playbackToken: token(type: "v")
thumbnailToken: token(type: "t", time: 2)
storyboardToken: token(type: "s")
}
}- One response shape for every asset.
- Asking for
tokenon a public ID costs nothing: it returnsnullwithout signing anything. - Always returns whatever playback ID the asset has.
For assets with both kinds of ID, or for testing: split by policy with aliases.
fragment MuxVideoByPolicy on MuxAssetInterface {
signedPlaybackIds: playback_ids(policy: "signed") {
id
playbackToken: token(type: "v")
}
publicPlaybackIds: playback_ids(policy: "public") {
id
}
}- Use it when an asset can have both, and you need a specific one.
- If an asset only has the other kind, that list is empty
[]. Handle that case. - Give both fields an alias. An unaliased
playback_ids(policy: "public")looks like "all playback IDs" to anyone reading the response.
A null token doesn't mean "public"
token is null in four situations. Decide what to do from policy, not from whether a token came back:
policy | token | Meaning |
|---|---|---|
public | null | Public video: play without a token |
signed | value | Signed video: play with the token |
signed | null | Misconfigured: schema lacks the permission, no signing key exists, or signing failed |
const pb = asset.playback_ids[0];
if (pb.policy === 'signed' && !pb.playbackToken) {
// Don't render a player that will get a 403: log and show a fallback.
}Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
403 on a signed stream, image or download | No token, or a token of the wrong type (e.g. a v token on a thumbnail) | Use the matching type: see Token types |
| Player plays, but no poster or timeline previews | thumbnail-token or storyboard-token missing | Pass all three tokens to <mux-player> |
403 only when opening a URL directly in the browser | A restriction blocks requests with no referrer | Expected. Test inside a page, or allow no-referrer in the restriction. |
404 Not Found on every signed URL | The default playback restriction was deleted in Mux | Choose another default, or clear it. See Playback Restrictions. |
400 Invalid playback restriction ID | The restriction ID is mistyped | Copy it from Mux → Playback Restrictions |
403 after a while on cached pages | Your cache outlives the token | Shorten the cache or raise expiresIn. See Caching pages that contain tokens |
Signed thumbnail ignores ?width= in the URL | Signed URLs ignore query parameters | Pass width to the helper or GraphQL field, so it goes in the token |
token and signed URL fields are null in GraphQL | Schema lacks the permission | Enable Generate signed playback tokens and URLs on the schema |
null tokens in Twig and GraphQL; CP shows "Must create Signed Keys…" | No signing key | Create one under Mux → Signed Keys |
GraphQL error Variable "$x" is never used | A variable is declared but not used in the query | Remove the variable or use it. GraphQL rejects unused variables. |
GraphQL error Invalid token type | type isn't one of v, t, g, s (or their long names) | Fix the type argument |
Caption URL returns 404 (not 403) | The token is fine, but the track no longer exists on Mux | Re-sync the asset (php craft mux/sync/all) |