Backend language examples
Understand the common playback flow and find the exact callback to modify in Node.js, Django, Laravel, PHP, ASP.NET or Java.
Your website decides who can watch#
Keep your login, purchases, membership and enrollment system. Your application supplies the current user and the authorized Content ID. The SDK calls DRM-X and the player loads the protected video.
One connection to your existing application
You own the login and permission decision. The SDK and player handle protected playback.
- Keep your login
The viewer signs in through your existing website.
- Connect your lookup
Your application checks access and returns the DRM-X Content ID for the selected lesson.
- Call through the SDK
The backend SDK uses server credentials to request authorized playback from DRM-X.
- Show the player
The player obtains a DRM license and plays the published encrypted content.
Understand the two video IDs#
| Value | Example | Where it comes from |
|---|---|---|
| Website video ID | lesson-123 | Your lesson, product or video record. |
| DRM-X Content ID | your-published-content-id | The protected content published in DRM-X. |
| User ID | customer-456 | Your authenticated login session. |
Map your lesson to its Content ID using your existing database, API or application code. Finding a video does not prove that this user may watch it; check permission before returning it.
Prepare once, then integrate#
- Encrypt and publish one video and copy its Content ID.
- Create playback credentials for the same environment. Use Site ID, Site Key and Access Key on the server.
- Download the complete kit or your platform kit. Install its SDK using your package manager.
- Connect your user/content permission callback, then add the player to your page.
The SDK operates on already-published content. It does not replace the packager or your payment system. Third-party runtime dependencies may need internet access during installation.
Choose your language#
Choose a language to focus the edit map.
Node.js / Express
Edit your application: server.mjs
Connect: authorize(userId, videoId)
Return an authorized content mapping or null. Read the user from your existing login middleware.
Python / Django
Edit your application: authorization.py
Connect: authorize(user, video_id)
Return a dictionary with content_id, or None. Register it as DRMX['AUTHORIZE'] in settings.py.
PHP / Laravel
Edit your application: app/Services/DrmxAccess.php
Connect: ContentAuthorizer.authorize(user, videoId)
Return an authorized content array or null. Bind your service in AppServiceProvider.
Plain PHP
Edit your application: index.php
Connect: findAuthorizedVideo(userId, videoId)
Return an authorized content array or null. Connect your existing PHP session identity.
C# / ASP.NET Core
Edit your application: Program.cs
Connect: QuickStartCatalog.FindAuthorizedVideoAsync
Return QuickStartVideo or null. IDrmXContentEntitlement verifies the requested Content ID against that result.
C# / ASP.NET Framework
Edit your application: App_Code/DrmXPlayback.cs
Connect: ApplicationServices.Authorize
Return true only for an authorized user, Content ID and content type. This is a source adapter for Windows/IIS.
Java / Spring Boot
Edit your application: DrmxAccess.java
Connect: ContentEntitlement.authorize(userId, videoId)
Return Optional<AuthorizedVideo> or Optional.empty(). Connect the controller and entitlement bean to your existing repository.
Configure your server#
| Examples | Environment variables |
|---|---|
| Node, Django, Java, PHP SDK, Laravel | DRMX_SITE_ID, DRMX_SITE_KEY, DRMX_ACCESS_KEY |
| ASP.NET Core and Framework | DRMX_PLAYBACK_SITE_ID, DRMX_PLAYBACK_SITE_KEY, DRMX_PLAYBACK_ACCESS_KEY |
Load these in the server process. Content ID is a per-video business value; do not overwrite shared credentials or global configuration to switch users or videos. Keep policy selection on the server.
PHP: connect your existing website#
Preview SDK, application example and source. Keep the extracted folder layout.
All platforms and complete kit · Understand the integration process
- Configure
Server environment
Set DRMX_SITE_ID, DRMX_SITE_KEY and DRMX_ACCESS_KEY.
- Authorize
examples/sdk/php/index.phpEdit findAuthorizedVideo($userId, $videoId) and read your existing session user ID.
- Embed
Your lesson page
Reuse the player markup and retain the selected videoId in the session endpoint.
cd examples/sdk/php
composer install
# Set server credentials and DRMX_LOCAL_DEMO=1 for a localhost demo only.
php -S 127.0.0.1:8106 index.phpFor the first test, replace your-published-content-id inside findAuthorizedVideo. Open http://127.0.0.1:8106/?videoId=1 and use Local demo sign in. PHP needs cURL and ZIP support; use PHP 8.2 or later.
For your application, replace the demo function with your own lookup. The following repository call is illustrative; implement it using your database:
function findAuthorizedVideo(string $userId, string $videoId): ?array {
$video = customerFindAuthorizedVideo($userId, $videoId);
if ($video === null) return null;
return ['contentId' => $video['drmx_content_id'],
'contentType' => 'vod', 'title' => $video['title'],
'policy' => 'multi-tier-standard'];
}Read $userId from normal server-side authentication. Retain the origin, request validation and exact content/type checks in the example. Choose a policy matching the published content. The PlaybackClient performs the DRM-X request; it cannot infer your purchase rules.
Other languages and API integration#
Go, Ruby and other server languages can call the Playback Session API after authenticating the user and checking content access. This release does not include Go or Ruby SDK libraries. Prefer the packaged SDK for the seven integration paths above.
Check before going live#
- Sign in as an allowed user and play a published video in a supported browser.
- Try signed-out and unpaid users, then revoke or expire access. New session requests must be denied.
- Change the browser Content ID or website video ID. The server must check the new selection.
- Set the exact public HTTPS origin, keep your framework’s session/CSRF protection, and disable demo identity code.
Existing sessions and DRM licenses have their own lifetimes. Permission changes are checked on new requests; they do not erase a license already issued.
PHP: run the complete demonstration website#
Try the live PHP demo · Download the complete PHP demo · SHA-256
Choose the PHP SDK example above for a small Composer-based integration in your existing website. Choose this complete demo for a ready-to-run website with playlist, token-proxy and diagnostics examples. The complete demo uses a source adapter and needs PHP 8.2+ with cURL, but no Composer or database. Both approaches keep credentials on your server and require your permission check.
- First playback
config/drmx.phpSet siteId, siteKey, accessKey, content.id, content.type and a matching licensePolicyTemplate. Keep the rest of the array.
- Your customers
src/bootstrap.phpConnect authenticated_user_id() to your login; replace user_can_play_content() with a fresh purchase, membership or enrollment check.
- Your video catalog
src/bootstrap.php + public/index.phpReplace the demo catalog helpers with your existing video lookup. Render only an authorized Content ID and type; retain server-side checks on every session request.
# Windows, inside the extracted drmx-php-sample folder:
powershell -NoProfile -ExecutionPolicy Bypass -File .\run-local.ps1
# macOS / Linux:
bash ./run-local.shOpen http://127.0.0.1:8086/ and press Play. Online playback resolves the registered manifest automatically. The local demo signs in a test viewer; this is only a first playback check.
For your website, set demo.allowLogin, demo.autoAuthenticateLocalhost and demo.autoAuthenticatePublicDemo to false in config/drmx.php, or disable their process-variable equivalents. Use your own login and current permission check; do not keep the demonstration session entitlement list as a purchase database. The supplied public/api/playback-session.php and playback-release.php handle the playback API; retain their request validation and content binding. Set the public document root to public/ and use your web server routing. The built-in launcher is for local testing.
Catalog helpers are demo_content_id(), demo_content_type(), player_playlist() and configured_content(). For a multi-video site, resolve these values from your existing catalog; your permission check must validate that exact selection. You do not need to synchronize purchases into DRM-X tables. Existing DRM licenses have their own lifetimes; revocation is rechecked for new sessions.
Use the included README for complete policy, hosting, token-proxy and native offline details. Before release, test authorized playback, denied and revoked users, content substitution, Stop and your supported browsers over HTTPS.
One Content ID, whichever storage you use#
No manifest URL is needed in your streaming integration. For 1aicloud or configured S3 storage, DRM-X uses the media URLs recorded when the package is published. For encrypted files uploaded to your own server, register their DASH/HLS media URLs in DRM-X first. Then use the same Content ID in PHP, ASP.NET or any other integration. Your server still checks the current user’s permission before requesting playback.
- Publish or register once
DRM-X content settingsConfirm the correct protected DASH/HLS media URLs are registered for your Content ID.
- Connect your website
Your authorization callback
Check login and purchase, membership or enrollment. Return the permitted Content ID.
- Play
DRM-X playback sessionDRM-X resolves the published package and returns the suitable manifest and DRM License Token.
If the registered manifest is missing, correct the publication or media URL registration in DRM-X. Do not add an arbitrary browser-supplied URL as a fallback. The complete PHP demo’s native offline endpoint is a separate advanced example; its current manual mapping is documented in advanced/OFFLINE.md.
DRM-X 6.0