MaxxiBoi
MaxxiBoi

Reputation: 78

Is there a way to only play videos in HTML5 if the user is logged in?

I want to make a Web page that has a video on it, but I only want the users to be able to see the video if they are logged in. The content requires a subscription, so I'll need to make a custom video player with HTML5 because the built-in video player on some browsers has a download button, and I don't want the user to be able to save the video on their device and put it on the Web so that everyone can see it for free. However, even if I do this, the user can still just open up developer tools, expand the video element, and see all of the URLs to the video.

    <video>
        <source src="./video.mp4" type="video/mp4">
        <source src="./video.ogg" type="video/ogg">
        <source src="./video.webm" type="video/webm">
    </video>

Then, the user can just navigate to one of those URLs, effectively bypassing anything that I set up. Actually, I might be able to prevent the user from navigating to one of those URLs, kind of like YouTube, but that doesn't mean that the user won't be able to use something like https://www.onlinevideoconverter.com/ to download the video.

I need a way to play the video without exposing the URLs in my frontend code. A solution with HTML5, CSS, and JavaScript without any additional libraries is preferred.

Upvotes: 0

Views: 161

Answers (2)

Brad
Brad

Reputation: 163303

The content requires a subscription, so I'll need to make a custom video player with HTML5 because the built-in video player on some browsers has a download button

Just turn off controls.

and I don't want the user to be able to download the video and put it on the Web so that everyone can see it for free

You can't do anything to prevent this. The content is trivially downloaded. The best you can do is implement DRM via Widevine or similar, but this is definitely not foolproof.

Upvotes: 0

Julien Ambos
Julien Ambos

Reputation: 2088

Serve the videos from a node.js express.js route that requires authentication and / or authorization to see. Take a look at https://github.com/deitch/cansecurity e.g.

Upvotes: 1

Related Questions