Protect streams with token authentication
A new Adaptive Media Delivery environment includes the Segmented Media Protection behavior, but its protections are switched off. Until you turn one on, anyone who gets hold of a manifest URL can play your stream. Token authentication closes that gap: your origin issues a short-lived token tied to an authenticated session, and edge servers refuse any request that doesn't carry a valid one.
This is the recommended authentication method for Adaptive Media Delivery. It's generally invisible to end users and needs no player changes.
Don't combine it with Auth Token 2.0 in the same ruleToken authentication through Segmented Media Protection gives you stronger protection than Auth Token 2.0 Verification. You can't use both in the same rule, though you can use them in separate rule sets with different match criteria.
When to use this
- You sell or gate access to content and need to stop link sharing.
- You want playback authorization enforced at the edge rather than at your origin.
- You're planning to add media encryption or access revocation, both of which build on this.
Where token auth sits in the protection stack
Akamai offers several layers, and they stack:
| Level | Protection | Where it's configured |
|---|---|---|
| — | Open access | No protection. Anyone can access your content. |
| 1 | Token authentication | Segmented Media Protection — this topic. |
| 2 | Geo protection | Restrict where your content can be played |
| 3 | HTTPS protection | Secure delivery on your service hostnames. |
| 4 | Media encryption | Encrypt media segments at the edge |
| Most | DRM encryption | A DRM license per playback environment, with rights management rules. |
How it works
Two tokens are involved.
- The access token (the "short token"). A one-time token that signifies the user session is authenticated. Your origin generates it and delivers it to the player as a query string, cookie, or header. Edge servers validate it against the shared secret you configure.
- The session token (the "long token"). Valid for the duration of the media stream, protecting the stream elements delivered during that session — media keys, manifests, and segments. Akamai generates it automatically after the access token validates.
The exchange:
- The player requests the manifest with the access token attached:
<URL>?hdnts=<token>. - Edge servers validate the HMAC inside the access token and check that it hasn't expired.
- Edge servers validate the session policy — that the token's
urloraclfield covers the requested URL, and, if the token carries anipfield, that the request comes from that client IP. - On success, the manifest is returned along with a session token:
<URL>?hdntl=<token>. - The player reads the manifest and requests a segment, returning the session token as a cookie or query string.
- Edge servers validate the session token and serve the segment. This repeats for every remaining segment.
- The session token expires and the link stops working. Its TTL is the full duration of the requested media item or one day (86,400 seconds), whichever is shorter.
The player never touches the cookie token — the browser handles it transparently. But cookie-based session tokens require that all stream elements live on the same domain as the manifest, and that the device supports cookies.
Before you begin
- Plan the origin-side work. Token generation runs on your infrastructure, not on Akamai. Do this before you activate the environment on production, or you'll deny every request.
- Keep
hdntsandhdntlout of your own query strings. Akamai reserves both names. - Decide where it applies. The default rule set covers all requests. If only part of your catalog is gated, put Segmented Media Protection in a custom rule set with its own match criteria instead.
1 - Enable token authentication in your environment
In the Segmented Media Protection behavior:
- Set the Token Authentication slider to On.
- Set the Encryption Key — a hexadecimal value acting as the trusted shared secret. Use an even number of characters, up to 32 total. For example,
eee7e9157f81b2f6d471bf2c. The cycle button generates a valid value for you. - Record this value. It's the
Keyyou use when generating tokens.
Don't activate on production or test on staging yet. Finish the token generation work below first.
Advanced options
Expand Show Advanced Options to reach these.
Transition key
A backup shared secret. If a token doesn't validate against the primary Encryption Key, edge servers retry with this key. That's what lets you rotate keys without locking users out — you start generating tokens with the transition key, let the old tokens drain, then update the encryption key.
Salt
An extra input during token generation that strengthens the token. As a best practice, don't override the default.
Request Headers for Session Token Salt
Instead of a static salt, you can bind the session token to properties of the playback session by naming request headers that feed the salt. Header names must be alphanumeric or hyphens, and a named header has to actually be present in player requests to be used. Headers present in a request but not named here are ignored.
| Header | Effect on the session-token-protected URL |
|---|---|
User-Agent | Can't be shared and played on a device with a different OS or browser. |
X-Playback-Session-Id | Can't be shared and played on two identical devices or browsers, and can't be shared between Apple and non-Apple devices in either direction. |
Origin | Can only be played by a JavaScript-based player on your intended website. |
Use Salt or Request Headers for Session Token Salt, not bothIf you define both, Salt wins and the request headers setting is ignored.
How salts interact with long token validation
Edge servers verify the long token found in an HTTP cookie even when the current request is for a master manifest, because an .m3u8 file can't be identified as master or variant. That produces two corner cases:
- A browser update can invalidate the long token. The cookie holding it has a 24-hour TTL. A browser update between two playback sessions inside that window changes the
User-Agentstring, which invalidates the token. - Request-header salts can invalidate the long token, because those headers change between consecutive playback sessions.
There's a fallback for this:
| Long token source | Result when long token validation fails |
|---|---|
| The HTTP cookie | Fallback. Validation falls back to the short token, if one is present. |
| The query string, URL path, or a request header | Failure. The request is denied with HTTP 403. |
Field carry-over
These options control which fields are carried from the access token into the session token, for access control and analysis.
| Field | What it does | When to enable it |
|---|---|---|
| Session-Id (enabled by default) | Carries session_id across. | Keep it on — it lets you track and count unique playback sessions, and it's required for token-based access revocation. |
| Data/Payload | Carries the data/payload field across. | When you want opaque data available for log analysis on session-token-protected URLs. |
| IP | Carries the ip field across, limiting access to that address. | Only when the player's IP won't change mid-session. Mobile clients switching between Wi-Fi and cellular will break. |
| ACL | Carries the acl field across, limiting access to the URL or path in that field. | Only when the master playlist, variant playlists, and segments share a base path. Playback fails if they don't. |
2 - Add cookie-less token auth if your devices need it
By default the session token comes back as an HTTP cookie. Some devices and browsers don't support cookies — Apple Safari and HLS devices commonly don't. Cookie-less token auth rewrites your manifest so the token is embedded in the URL path of segment requests instead, which means a client only needs to be able to fetch objects over HTTP.
For DASH streams: in Token Authentication Additions for DASH, set Token in Query String to On.
For HLS streams:
- In Token Authentication Additions for HLS, set Token in URI to On.
- Enter your master manifest filenames in Master Manifest Files. Common HLS master manifest names are prefilled; add or remove as needed.
- Filenames can contain alphanumeric and dot characters.
- An asterisk works as a wildcard across a range of filenames.
- Make sure the names you enter can't also match your variant manifest files.
Cookie-less limitations
| Limitation | Detail |
|---|---|
DASH SegmentBase and SegmentList manifests | SegmentTemplate is fully supported. SegmentBase isn't supported if you also use media encryption for DASH — encryption is applied first in the request queue, so enabling both returns 400 Bad Request. SegmentList isn't supported at all; content still gets delivered, but cookie-less token auth isn't applied. DASH-IF doesn't recommend SegmentList either. |
| DASH live can't use strict token mode | Strict mode (via_query_string_strict) requires a short token, and live playback re-requests the manifest roughly every 30 seconds — longer than a short token stays valid. VOD supports both strict and non-strict modes. |
| HLS streams without a master manifest | Not supported. In practice this isn't a constraint, since adaptive bitrate streams carry rendition information in the master manifest. |
| Media encryption from origin | If your media is pre-encrypted on the origin, the manifest and segment URLs can't be rewritten to carry the token. |
| Absolute segment URLs in HLS | The session token cascades from the rewritten master manifest down to segments, so segment URLs in the variant manifest must be relative. This affects media segments, ad segments, and #EXT-X-MAP media initialization segments. |
| Multi-CDN | Not supported. Manifest rewriting is unique to Akamai edge servers. You also can't have this environment serve assets through another Adaptive Media Delivery configuration that has cookie-less token auth disabled. |
| Multiple Akamai-served hostnames | If your manifests reference several Akamai-served hostnames, the encryption keys must be identical across all of them. |
3 - Generate the access token on your origin
The access token is a delimited list of string fields with an HMAC that prevents tampering. Edge servers verify each field.
| Field | Required | Notes |
|---|---|---|
token_name / tokenName | Yes | Must be hdnts. |
start_time / startTime, end_time / endTime | Yes | Set the token's TTL. |
session_id / sessionId | No | A unique identifier for a single playback session. Printable ASCII, 64 bytes or less. Required if you use token-based access revocation. |
key | Yes | The secret used to generate the token — the Encryption Key you set above. Can also be the Transition Key, or either key combined with the Salt / request headers if you configured those. |
Think twice about the IP fieldDon't tie tokens to a specific IP address unless every request genuinely originates from one. It breaks delivery when requests come from other addresses, and in IPv4+IPv6 dual-stacked environments.
Akamai publishes token generation SDKs that handle all required and optional fields:
4 - Apply the token to your content
Attach the token to the manifest or index file URL as a query string parameter, cookie, or request header:
<URL>?hdnts=<token>
A complete example, with the token in the query string:
http://www.mymedia.com/<path>/media.m3u8?hdnts=st=1370627194~exp=1370627409~acl=*~hmac=6a10b3f602ffde88c02cd1b89665bfdfdc0fc84c3cf7049752931ad7
Ideally your origin generates a token per client request, so the token can be scoped to a single authorized user.
Caveats and known issues
| Issue | Description |
|---|---|
| Standard token auth requires cookie support | Typically a problem on Apple Safari and HLS devices. Either your users enable cookies (in Safari, Preferences > Security > Accept Cookies: Always), or you use cookie-less token auth. |
| Airplay breaks if the short token has expired | Starting playback on an iOS device and then Airplaying to an Apple TV (or the reverse, mid-stream) fails if the initial short token has expired. X-Playback-Session-ID also changes during Airplay. Manage short token expiry accordingly. |
Origin as a salt plus a redirect behavior denies requests | If a Redirect behavior or Site Failover is configured and the redirect URL uses a different host, the browser sets Origin to Null for the first redirect, then restores it. With Origin in the salt, the request is denied. |
Salt overrides Request Headers for Session Token Salt | Define only one of them. |
| Two token auth behaviors in one rule | Segmented Media Protection and Auth Token 2.0 Verification can't coexist in the same rule. Use separate rule sets with different match criteria. |
Related
Updated about 1 hour ago
