Step 1. Verify PHP is installed and running
Because the primary goal of authentication tokens is to provide a level of security, we generate them server side. We will use PHP to generate the authorization tokens, so the rest of the steps in this tutorial require that PHP be installed and running. Although PHP is used here, any server-side language and environment can be used. Let’s test your installation with a quick script.
Put the following code into a file called uplynkhw.ph and place it in a directory from which your server knows how to serve PHP files.
1 2 3
<?php echo “Hello, World from PHP!”; ?>
To ensure the file is being served correctly, load uplynkhw.php in your browser. You should see the words "Hello, World from PHP!" If you see anything else, including the code you inserted into the file, check your PHP installation on your web server.
Step 2. Convert player.html to player.php
Rename player.html from the previous tutorial to player.php and place it in your PHP-enabled directory. Load it in your browser and ensure your content plays.
Step 3. Enable DRM to (intentionally) break playback
- In the upLynk CMS, select the asset you're using in player.html.
- Select the Advanced tab in the Editor pane.
- Check "Require a token for playback" and click .
Return to your browser, reload player.php, and notice that the content will no longer play. Playback is not permitted without a valid authorization token. Because no such token is present, the upLynk system correctly prevents playback from happening.
Step 4. Add token generating code
Modify player.php to the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
The PHP code we’ve added provides a function that generates the authorization token. In short, our function sets an expiration time of 300 seconds, sets an asset's content type, extracts the content ID from the playback URL, creates a hash from the user’s IP address, combines all of that together with your API key to create the signature and ultimately combines everything into a tokenized playback URL that will allow playback. The recommended expiration for production tokens is 20-60 seconds.
The PHP code we included in the body of the document serves to call our earlier defined function and insert the playback URL into the resulting HTML.
Reload player.php and playback of the content should begin. Playback works because a valid authorization token was appended to the content playback URL. The upLynk system inspected the token, verified its authenticity, and permitted playback.
At this point you can see that although this page allows playback for any visitor, you can now add server-side logic to conditionally allow playback. Future tutorials will go into specific cases of selective logic such as requiring a user login before playback, or filtering access to content based on their geographic location.
Step 6. Testing authorization tokens in the upLynk CMS
After you’ve familiarized yourself with the upLynk Digital Rights Management Documentation you will learn that there are optional arguments that can be combined in tokens to change their behavior, giving you greater flexibility when it comes to access control. To assist you in debugging your tokens the upLynk CMS provides a form that will validate your generated tokens. Let’s test this now.
- Refresh player.php so we have a fresh token.
- View the source of player.php in your browser.
- Find the playback URL in the source code. Locate and copy your .m3u8 URL including the querystring (everything after the ‘?’).
- Open upLynk CMS in your browser.
- In the upper right hand corner click your login name and select Account Settings.
- Select the Playback Tokens tab on the left.
- Under Test tokens, paste the playback URL with the auth token into the text field. Click .
- A popup will show you the results of the token validation testing.
In the next tutorial, we will build on this example and introduce a real world use case using DRM to restrict playback to registered users that are logged into an application.Back to tutorials