This guide explains how to create a signature, and the required and optional fields for signatures.
To create a signature, you compose a string to sign, which we refer to as a signed value in this guide. The signed value includes parameters that describe the content you are protecting, the expiration time of the signed value, and so forth.
You use the signed value while creating a signature string. You create a signature string by composing the parameters for the signature, such as an asymmetric-key Ed25519 signature of the signed value.
Media CDN uses the final composed signature to help protect your content.
Supported signing formats
Media CDN supports the following signed request formats.
Format | Behavior | Example |
---|---|---|
Query parameters (exact URL) |
Exact URL, for granting access to a specific URL. |
Exact:
|
Query parameters (URL prefix) |
Specifying a URLPrefix lets you sign a prefix and append
the same query parameters to multiple URLs within your player or manifest
generation.
|
What to sign:
Replace |
Path component |
Prefix: allows access to any URL with a prefix prior to the
This allows relative manifest URLs to automatically inherit the signed URL component when fetching sub-resources. |
https://media.example.com/video/edge-cache-token=Expires=EXPIRATION
|
Signed cookie | Prefix: the cookie allows access to any URL with the prefix specified
in the signed URLPrefix value.
|
Edge-Cache-Cookie:
|
Create a signature
Create a signed value by concatenating a string that contains the required signature fields and desired optional signature fields.
If specified,
URLPrefix
must come first, followed byExpires
,KeyName
, and then any optional parameters.Separate each field and any parameters with the following:
- For cookies, use a colon
:
character. - For query parameters and path components, use an ampersand
&
character.
- For cookies, use a colon
Sign the signed value with an Ed25519 signature.
Append a field separator (either
:
or&
) followed bySignature=
and the Ed25519 signature to the end of the string.
Create a signed URL
The following code samples shows how to programmatically create a signed URL.
Go
To authenticate to Media CDN, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Media CDN, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Create a signed URL prefix
The following code samples show how to programmatically create a signed URL prefix.
Go
To authenticate to Media CDN, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Media CDN, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Create a signed URL cookie
The following code samples show how to programmatically create a signed URL cookie.
Create a signed path component
The following code samples show how to programmatically create a signed path component.
Python
To authenticate to Media CDN, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Required signature fields
The following fields are required for every signature:
Expires
KeyName
Signature
If query parameters are present, they must be grouped together as the last parameters in the URL. Unless otherwise specified, parameter names and their values are case-sensitive.
The following table explains each parameter:
Field name | Signature parameters | Signed value |
---|---|---|
Expires |
Integer seconds that have elapsed since the Unix epoch (1970-01-01T00:00:00Z) | Expires=EXPIRATION_TIME , after which the
signature is no longer valid. |
KeyName |
The name of the EdgeCacheKeyset used to sign this
request. KeyName refers to the entire keyset, not
individual keys within the keyset itself.
|
KeyName=EDGE_CACHE_KEYSET |
Signature |
A base-64 encoded version of the signature. | Not applicable |
Optional signature fields
If query parameters are present, they must be grouped together as the last parameters in the URL. Unless otherwise specified, parameter names and their values are case-sensitive.
The following table explains each parameter's name and detail for optional signature parameters:
Field name | Signature parameters | Signed value |
---|---|---|
HeaderName |
A named request header field name that must be present in the request. Must be lowercase when signed because header field names are case-sensitive. Media CDN lowercases the header before validating the signature. |
HeaderName=HEADER_NAME |
HeaderValue |
A named request header field value that must be present in the
request. This is commonly a user ID or other opaque identifier. Requests
with HeaderValue but without HeaderName are
rejected.
|
HeaderValue=HEADER_VALUE |
IPRanges |
A list of up to five IPv4 and IPv6 addresses in CIDR format for
which this URL is valid in web-safe base64 format. For example,
to specify the IP ranges "192.6.13.13/32,193.5.64.135/32", you specify
IPRanges may not be helpful to include in signatures when clients are
at risk of WAN migrations or cases where the network path to your
application frontend is different than the delivery path.
Media CDN rejects clients with an The following are cases that may result in Media CDN
rejecting clients with an
All of these factors can contribute to a given client having a
non-deterministic IP address during a video playback session. If the
client IP address changes after you have issued access, and the
client attempts to then download a video segment into their playback
buffer, they receive an |
IPRanges=BASE_64_IP_RANGES |
URLPrefix |
The base64 (URL-safe) URL prefix to grant access to. Specifying a
URLPrefix lets you sign a prefix and append the same query
parameters to multiple URLs within your player or manifest generation.
The URLPrefix is required when using the signed cookie
format.
|
URLPrefix=BASE_64_URL_PREFIX |