Last update:2025-09-05 17:34:19
This guide explains how to configure and use token authentication (also known as timestamp anti-hotlinking). This security feature is designed to protect your live streaming content from unauthorized access and hotlinking.
By adding an encrypted token and a timestamp to your streaming URLs, you can control who can access your streams and for how long. This ensures that only users with valid, time-limited URLs can view your content, securing your streams and preventing unauthorized distribution.
The authentication process involves three main components:
When a viewer tries to access a stream using an authenticated URL, our edge servers will:
If the tokens match and the URL has not expired, the viewer is granted access to the stream. Otherwise, the request is denied.
To enable and configure token authentication, follow these steps:
Here is a detailed explanation of each field in the configuration panel:
| Field | Description | Example/Default |
|---|---|---|
| Application name | Specify the application(s) where this rule should apply. Leave blank to apply to all.Note: This application name must match the one you configured for your current domain. | live,vod |
| Signature Parameter Name | The name of the URL parameter for the encrypted token. | Default: wsSecret |
| Timestamp Parameter Name | The name of the URL parameter for the timestamp. | Default: wsTime |
| KEY | Your private secret key used to generate the encrypted signature for the token. | mysecretkey |
| Encryption Time Format | The format for the timestamp. | UNIX timestamp or Hexadecimal |
| Expiration Time | How the URL’s expiration is handled. See details on each option below. | By Duration, By Absolute Time, By Valid Time, or No validation time. |
| Duration | The link’s valid duration in seconds. (Required for “By Duration”). | 3600 (for 1 hour) |
| Time Tolerance | This sets a time tolerance (in seconds) to prevent valid URLs from failing due to minor time differences between your server and our edge servers. It accommodates for clock skew. | 300 (for 5 minutes) |
| Signature Components | The formula used to generate the token. | KEY+Path+Time is common. |
wsTime (the timestamp in the URL) + the configured Duration. This is the most common and simple method.wsABSTime) containing the exact UNIX timestamp of expiration. The hash is calculated using this absolute expiration time.wsKeepTime parameter. This provides flexibility, as your server can generate links with different lifespans without changing the console configuration. The hash calculation includes both wsTime and wsKeepTime.wsSecret token to ensure the request is signed with the correct key, but it will not check if the timestamp (wsTime) has expired. This is less secure and primarily used to validate the origin of a request without time constraints.Once you have configured the feature in the console, you need to update your application or backend server to generate the dynamic, authenticated URLs for your users.
The core logic is to create a string based on your chosen Ciphertext Combination Method and then calculate its MD5 hash. Note: The exact components included in the string to be hashed can vary depending on the Validity Period method you choose.
Let’s assume your configuration is as follows:
mysecretkeyKEY+PATH+TIMEwsSecretwsTimeUNIX timestamp3600 seconds (1 hour)http://your.domain.com/live/stream1.flvHere’s how to generate the signed URL on your server:
/live/stream1.flv.1678886400.string_to_hash = "mysecretkey/live/stream1.flv1678886400"string_to_hash.wsSecret_value = md5("mysecretkey/live/stream1.flv1678886400")b1b5c2c7e8e5e8e5c2c7b1b5c2c7e8e5.http://your.domain.com/live/stream1.flv?wsSecret=b1b5c2c7e8e5e8e5c2c7b1b5c2c7e8e5&wsTime=1678886400A viewer using this URL will have access to the stream until 1678886400 + 3600 = 1678890000.
This method is useful when you want to define the validity duration dynamically for each URL you generate. Let’s assume your configuration is the same as the previous example, but you’ve selected By Valid Time.
mysecretkeyKEY+PATH+TIME (Note: The wsKeepTime value is appended after the timestamp in the hash calculation for this mode).wsSecretwsTimeUNIX timestamp7200 seconds (2 hours)https://your.domain.com/live/stream1.sdpHere’s how to generate the signed URL on your server:
/live/stream1.sdp.1678886400.7200.wsKeepTime value).string_to_hash = "mysecretkey/live/stream1.sdp16788864007200"wsSecret_value = md5("mysecretkey/live/stream1.sdp16788864007200")20722b11be862a6563657a70a8a8167.wsSecret, wsTime, and wsKeepTime as query parameters.https://your.domain.com/live/stream1.sdp?wsSecret=20722b11be862a26563657a70a8a8167&wsTime=1678886400&wsKeepTime=7200This approach provides more flexibility by allowing the URL-generating server to set the expiration on the fly.
This method is ideal when you need a link to expire at a precise moment, regardless of when it was generated.
mysecretkeyKEY+Path+Time (Note: The “Time” in the hash is the absolute expiration time).wsSecretwsABSTime (This parameter name must be configured in the console).UNIX timestamp1678890000 (This is the exact UNIX timestamp when the URL will become invalid).https://your.domain.com/live/stream1.m3u8Here’s how to generate the signed URL on your server:
/live/stream1.m3u8.1678890000.string_to_hash = "mysecretkey/live/stream1.m3u81678890000"wsSecret_value = md5("mysecretkey/live/stream1.m3u81678890000")a3f9b2c8d7e6f5a4b3c2d1e0f9a8b7c6.wsSecret and the wsABSTime as query parameters. https://your.domain.com/live/stream1.m3u8?wsSecret=a3f9b2c8d7e6f5a4b3c2d1e0f9a8b7c6&wsABSTime=1678890000This URL will be valid until the exact timestamp 1678890000 is reached.