Skip to main content

Playback tokens (JWT)

A playback token is a signed JSON Web Token (JWT) that lets a player watch specific streams for a limited time. When secure playback is enabled, a player without a valid token can't play the protected streams. This page shows where to create tokens, every option a token can carry, and how to use it in the player.

Before you start​

  • Secure playback must be enabled, for your whole organisation or for single streams. On for the organisation, every stream needs a token; on for a stream, only that stream does. To protect single streams, contact us. Check it at https://dashboard.nanostream.cloud/organisation under Enabled Packages (Secure). If it shows Upgrade needed, contact us. The Builder Hub account menu also shows Secure playback as On or Off.
  • Use a separate organisation for testing, so turning on secure playback doesn't stop your production streams.
  • Role: nanoAdmin and nanoUser can create playback tokens; nanoReadOnly can't.
note

Playback tokens are not API credentials. They only authorise playback. To call the nanoStream APIs you use an API key or an access token (bintu token); see APIs & SDKs overview.

Set it up​

The Builder Hub is quickest for trying it out, the Dashboard gives you every option in a form for manual tokens and events, and the token API is for production. For production, always create tokens on your backend, per viewer, with the tightest restrictions you can. See Security best practices for a complete backend example.

VideoSecure playback token tutorial

Who can use it: free account or existing customer, with secure playback on. Guests see token creation marked Sign in and can only run the revocation demo. Without secure playback, the bar reads Secure playback is not on your account yet. with Upgrade.

Open Build › Security › Manage tokens. It has three cards: Create an access token, Create a playback token and Revoke playback tokens.

  1. Click Create a playback token.
  2. Under For, pick one of your streams (live ones are marked (live)), or Every stream of your account.
  3. Under Valid for, choose 1 hour, 24 hours, 7 days or 30 days.
  4. Optionally enter a Tag, for example partner-site, to recognise the token later.
  5. Click Create playback token.

What you get: under Your token, the token with Copy (the hub doesn't keep it, so copy it now); a Viewer link that plays the stream with the token; the player code that hands the token to the nanoStream Player (security: { jwtoken: '<the token>' }); and a preview Playing with this token. To create tokens from your own server, use the API tab.

[!WARNING] A token for every stream that leaks plays all of them until it expires. For a live service, create short tokens for one stream on your server and give each viewer their own.

Create an access token is for your server, scripts and dashboards rather than players: it lets them call the nanoStream REST API and the Analytics API instead of your API key.

  1. Click Create an access token.
  2. Under Valid for, choose 1 day, 7 days, 30 days, 90 days or 1 year (the maximum).
  3. Under For, tick the APIs it may call: the bintu API (streams, their settings and states) and the Analytics API (viewers, usage and quality).
  4. Optionally add a Note, then click Create access token.

You get the token, its expiry and token id, and a ready curl line for each API (header x-bintu-token or x-access-token). Quote the token id to support, never the token. An access token acts as you, with your role, and can't be revoked: pick the shortest expiry that works. If your role can't create tokens with your sign-in alone, the hub asks you to confirm your email and password (Create with my password). Access tokens and API keys are explained in the APIs & SDKs overview.

Revoke playback tokens › Show token revocation demonstrates revocation on our demo stream, guests included. See Token revocation & session control.

MessageWhat to do
Secure playback is off for …Your streams play without a token, so there's nothing to create. Click Ask for secure playback to request it.
The token could not be created: …Check that you're signed in with a role that may create tokens (nanoAdmin or nanoUser).
Pick at least one API.Tick the bintu API, the Analytics API, or both.
That email and password don't match.Re-enter your login when confirming your password.
A hub player says Secure playback is on, and no playback token could be created.Sign out and sign in again with an admin login of your organisation.

Token API​

POST https://token.nanostream.cloud/api/v1/splay
Content-Type: application/json
X-BINTU-TOKEN: <YOUR_BINTU_TOKEN>

Authenticate with either header:

HeaderCredentialRecommendation
X-BINTU-TOKENAccess token (bintu token): temporary, role-scoped, can be invalidatedRecommended
X-BINTU-APIKEYOrganisation API key: permanent, full accessOnly on your backend
EXP=$(( $(date +%s) + 1800 )) # expires in 30 minutes

curl -X POST https://token.nanostream.cloud/api/v1/splay \
-H "Content-Type: application/json" \
-H "X-BINTU-TOKEN: <YOUR_BINTU_TOKEN>" \
-d '{
"groupid": "<STREAM_GROUP_ID>",
"exp": '"$EXP"',
"ip": "203.0.113.10",
"domain": "watch.example.com",
"user": "user-4711",
"tag": "table 7",
"revocable": true,
"forceDisconnect": false
}'

Response:

{
"success": true,
"data": {
"token": "<YOUR_JWT>"
}
}

Full API reference: https://api.nanostream.cloud/docs/token/

Request fields​

Include exactly one scope field (groupid, streams or orgawide). Everything else is optional.

FieldTypeDescription
groupidstringStream group ID. The token plays every stream (rendition) in the group, so one token covers ABR.
streamsarray of stringsOne or more stream names, e.g. ["XXXXX-YYYY1","XXXXX-YYYY2"].
orgawidebooleantrue: all streams of your organisation. Avoid in production.
expnumberExpiry, UNIX timestamp in seconds. See Lifetime.
nbfnumber"Not before": the token is invalid before this UNIX timestamp (seconds).
forceDisconnectbooleanDefault false. true ends active sessions when the token expires.
revocablebooleanDefault false. true lets you revoke the token; limits lifetime to 24 hours.
domainstringWeb application domain the player must run on (referrer), e.g. example.domain.com.
ipstring or arrayOne IPv4 address or CIDR range ("198.51.100.0/24"), or an array of up to 10 addresses and ranges, mixed.
userstringUser ID, name or alias for traceability.
tagstringFree-text tag, e.g. an event or table.
custstring, up to 100 charactersOptional custom text stored in the token, for your own reference. It doesn't restrict playback.

Response codes​

CodeMeaningExample body
200Token created{"success": true, "data": {"token": "<YOUR_JWT>"}}
400Parameter missing{"success": false, "errorCode": 1000, "message": "Parameter required: ..."}
403Credential not valid{"success": false, "errorCode": 1001, "message": "Provided APIKey is not valid"}

If your organisation doesn't have secure playback, the token service answers with error code 5003 ("Not a secured organisation").

Lifetime​

Token typeMaximum lifetimeCan be revoked
Non-revocable (default)365 daysNo
Revocable ("revocable": true)24 hoursYes
Created in the Builder HubThe Valid for you pick: 1 hour to 30 daysYes for 1 hour and 24 hours; no for 7 and 30 days

Only the revocation demo on Revoke playback tokens uses 5-minute tokens, on nanocosmos's demo stream.

Always set exp yourself. Don't rely on the default lifetime.

We recommend a lifetime of 24 hours or less in general, and 5–30 minutes for high-security use cases. Longer non-revocable tokens can be acceptable for test pages and environments with lower security requirements. The 24-hour maximum for revocable tokens may change in the future.

What happens when a token expires​

An expired token can't be used to:

  • start playback or reconnect
  • switch streams or ABR renditions on an existing connection

Active sessions depend on forceDisconnect:

forceDisconnectActive sessions after expiry
false (default)Keep playing. Only new connections and stream switches are rejected.
trueDisconnected.

Token claims​

The token service signs the token. When you decode a token (for example in the Dashboard's overview), you see these claims:

ClaimMeaning
audAudience. splay for playback tokens.
issIssuer: nanocosmos.
subYour organisation ID.
jtiUnique token ID. Use it to find the token in the Guardian view of nanoStream Analytics.
iat, nbf, expIssued at, not before, expires (UNIX seconds).
streamsArray of stream names the token may play.
groupidStream group ID, for a group token.
orgahashYour organisation's hash, for an organisation-wide token (orgawide: true).
forceDisconnect, revocableSession and revocation behaviour.
tagYour tag, if set.

You can check a token with the verify endpoint (no authentication header needed):

curl -X POST https://token.nanostream.cloud/api/v1/splay/verify \
-H "Content-Type: application/json" \
-d '{"token": "<YOUR_JWT>"}'

200 means valid. 403 means invalid, e.g. {"success": false, "errorCode": 1002, "message": "jwt expired"}.

Use the token in the player​

Add a security object with jwtoken to the source. With a stream group:

var config = {
source: {
group: {
id: '<STREAM_GROUP_ID>',
security: { jwtoken: '<YOUR_JWT>' }
}
},
playback: { autoplay: true, automute: true, muted: true }
};

With entries (stream names):

var config = {
source: {
defaults: { service: 'bintu' },
entries: [
{
h5live: {
rtmp: { streamname: 'XXXXX-YYYYY' },
security: { jwtoken: '<YOUR_JWT>' }
}
}
]
}
};

You don't need different server URLs for secure playback with the JavaScript player. The player routes to the secure edge when a token is present. In the hosted iframe and demo player, pass the token as group.security.jwtoken=<YOUR_JWT> together with group.id=.

info

Domain-restricted tokens don't work with the hosted iframe embed. Use the JavaScript API on your own page. See Embed the player.

Use tokens outside the JavaScript player​

For external players and native apps, token-protected streams use the secure hosts and the jwtoken query parameter. These URLs are provided as-is, without the player's latency control:

# Low-latency MP4
https://bintu-splay.nanocosmos.de/h5live/authhttp/stream.mp4?url=rtmp://localhost/splay&stream=<STREAM_NAME>&jwtoken=<YOUR_JWT>

# Low-latency HLS (iOS / iPadOS)
https://bintu-splay.nanocosmos.de/h5live/authhttp/playlist.m3u8?url=rtmp://localhost/splay&stream=<STREAM_NAME>&jwtoken=<YOUR_JWT>

IPv4 and IPv6​

nanocosmos streaming systems operate over IPv4. Viewers on IPv6 are translated to IPv4 via NAT64, so IP restrictions in tokens use IPv4 addresses. To restrict an IPv6 client, obtain its public IPv4 address (for example with a service such as https://api.ipify.org) and put that address in the token.

Troubleshooting​

ProblemCause and fix
Player error, token "expired"Create a new token. Check that your server clock is synced (NTP).
Token valid, stream doesn't playWrong scope (stream not in streams/group), wrong domain, or the viewer's IP doesn't match ip. Decode the token and compare.
Token ignored in demo playerThe token parameter must match the source form: group.id + group.security.jwtoken.
Token has no effectThe organisation isn't secure-enabled, so playback is open anyway.
403, error code 1001API key or access token is invalid, or belongs to another organisation.
IP restriction blocks an IPv6 viewerUse the viewer's public IPv4 address.

Legacy STS tokens​

Before player 4.18.0, secure playback used a proprietary STS token format. STS is deprecated. Use JWT for all new integrations; see Legacy & retired docs if you still maintain an STS setup.

Next steps​

tip

Try it in the Builder Hub: sign in and open Manage tokens to create a playback token for your own stream and watch it play. Start for Free