I'm using CloudFront Signed URL to display images and videos from S3 to be secured.
It works well on images and other videos except for .m3u8 file.
I used AWS PHP SDK and here's my code.
<?php
// Instantiate the CloudFront client with your AWS credentials
$cloudFrontClient = new CloudFrontClient(array(
'region' => env('AWS_DEFAULT_REGION'),
'version' => 'latest',
'http' => [ 'verify' => false ],
'credentials' => array(
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
)));
// Create a signed URL for the resource
$resourceKey = 'https://abcdefg.cloudfront.net/test/file_1000k.m3u8';
$expires = time() + 3600;
$signedUrl = $cloudFrontClient->getSignedUrl([
'url' => $resourceKey,
'expires' => $expires,
'private_key' => public_path().'/pk-ABCD123.pem',
'key_pair_id' => 'ABCD123ABCD123ABCD123'
]);
?>
<video id='hls-example' class="video-js vjs-default-skin" width="640" height="480" controls>
<source src="<?php echo $signedUrl; ?>" type="application/x-mpegURL">
Your browser does not support the video tag.
</video>
<script src="https://vjs.zencdn.net/7.2.3/video.js"></script>
<script src="<?php echo asset('public/assets/js/videojs-contrib-hls.min.js'); ?>"></script>
<script>
var player = videojs('hls-example');
player.play();
</script>
If I'm not mistaken, it doesn't play because we need also to sign the segmented files (.ts) inside the .m3u8 file.
How can we dynamically change it?
Is there any way we can play .m3u8 file securely so that users can't use the direct link access to download the file?