Skip to content

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 ​

  1. Create a signing key. Go to Mux → Signed Keys and create one. The plugin signs every token with it.
  2. Upload videos as signed. Set Mux → Settings → Secure Playback to Secure. New uploads get a signed playback ID.
  3. Render with the helpers. In Twig, use getPlaybackToken() or the get…Url() helpers. In GraphQL, use the token or …Url fields on playback_ids.
  4. Headless only: enable Mux → Generate signed playback tokens and URLs on the GraphQL schema your server uses.
  5. Optional: set a Default Playback Restriction ID to limit which websites can play your videos.
twig
{% 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:

PolicyWho can watchURLs need a token
publicAnyone who has the playback IDNo
signedAnyone with a valid token for that IDYes

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 policy argument ('public' or 'signed'). Without it, the first playback ID is used, as in earlier versions.
  • GraphQL: each item in playback_ids has its own policy and its own tokens and URLs, so your frontend can choose. Use playback_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:

TypeNameUsed for<mux-player> attribute
vvideoHLS stream, captions/subtitles (.vtt), MP4/M4A downloadsplayback-token
tthumbnailStill images (thumbnail.jpg/png/webp), the player posterthumbnail-token
ggifAnimated previews (animated.gif/webp)—
sstoryboardTimeline 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 typeModifiers
v videomax_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 thumbnailtime (seconds), width, height, fit_mode (preserve, stretch, crop, smartcrop, pad), rotate (90/180/270), flip_v, flip_h
g gifstart, end (max 10 seconds long), width, height (max 640), fps (max 30)
s storyboardnone
all typesplayback_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.

twig
{# 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:

SettingDefaultMeaning
signedTokenLifetime86400 (24 hours)How long a token is valid when you don't ask for a lifetime
maxSignedTokenLifetime31536000 (365 days)The longest lifetime anyone can request. Larger requests are reduced to this.
signedTokenWindow3600 (1 hour)Rotation window: see below

Request a different lifetime per token with expiresIn (seconds):

twig
{{ video.getPlaybackToken('v', {}, 3600) }}            {# at least 1 hour #}
{{ video.getThumbnailUrl({width: 640}, 'jpg', 604800) }} {# at least 7 days #}
graphql
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.

CacheWhat the plugin doesWhat you do
Craft GraphQL response cacheExpires automatically when the window rotatesNothing
Twig {% cache %} blocksExpire automatically when the window rotatesNothing
Your own caches (SSR render cache, CDN, static build)Can't see themKeep 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_id to 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 permissionSigned playback IDPublic playback ID
Yestoken and URL fields filled intoken is null, URL fields filled in
Notoken and URL fields are nulltoken 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.

graphql
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 token on a public ID costs nothing: it returns null without 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.

graphql
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:

policytokenMeaning
publicnullPublic video: play without a token
signedvalueSigned video: play with the token
signednullMisconfigured: schema lacks the permission, no signing key exists, or signing failed
js
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 ​

SymptomLikely causeFix
403 on a signed stream, image or downloadNo 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 previewsthumbnail-token or storyboard-token missingPass all three tokens to <mux-player>
403 only when opening a URL directly in the browserA restriction blocks requests with no referrerExpected. Test inside a page, or allow no-referrer in the restriction.
404 Not Found on every signed URLThe default playback restriction was deleted in MuxChoose another default, or clear it. See Playback Restrictions.
400 Invalid playback restriction IDThe restriction ID is mistypedCopy it from Mux → Playback Restrictions
403 after a while on cached pagesYour cache outlives the tokenShorten the cache or raise expiresIn. See Caching pages that contain tokens
Signed thumbnail ignores ?width= in the URLSigned URLs ignore query parametersPass width to the helper or GraphQL field, so it goes in the token
token and signed URL fields are null in GraphQLSchema lacks the permissionEnable Generate signed playback tokens and URLs on the schema
null tokens in Twig and GraphQL; CP shows "Must create Signed Keys…"No signing keyCreate one under Mux → Signed Keys
GraphQL error Variable "$x" is never usedA variable is declared but not used in the queryRemove the variable or use it. GraphQL rejects unused variables.
GraphQL error Invalid token typetype 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 MuxRe-sync the asset (php craft mux/sync/all)