Skip to main content

Secure playback

Create Platform Authorizer

The PlatformCore or PlatformAuthorizer facilitates seamless interaction with all Quickplay platform services with industry standard security model. It is suggested to create one instance of platform authorizer and use it for one app session.

To create an instance of Platform Authorizer, one would require client Id, client secret, xClientId, authorization endPoint, headers(optional) and User Authorization Delegate. The client Id and secret would be provided while onboarding a customer onto Quickplay platform. The client app must implement and provide user authorization delegate which delivers the UMS token required for authorization with platform services.

The endPoints would be provided to a customer while onboarding onto Quickplay platform.

import {
platformAuthorizer,
PlatformAuthConfig,
UserAuthDelegate,
} from '@quickplay/rn-qp-nxg-player';

const platformAuthConfig: PlatformAuthConfig = {
clientID: ,
clientSecret: ,
endpointURL: ,
xClientID: ,
headers: {},
};

// Returns whether platform Authorizer is configured or not
if (!(await platformAuthorizer.isConfigured())) {
// Initialize platform authorizer
await platformAuthorizer.initWithConfig(platformAuthConfig, false);
}

const userAuthDelegate: UserAuthDelegate = {
async fetchUserAuthorizationToken(): Promise {
// Returns the UserAuthorizationToken.
},
};

platformAuthorizer.setUserAuthDelegate(userAuthDelegate);

// Triggers platform authorization
let authToken: AuthorizationToken | null = null;
authToken = await platformAuthorizer.ensureAuthorization();
note

At any point of time only one instance of PlatformAuthorizer could be created and it is suggested to use this instance for the complete application session. The existing PlatformAuthorizer instance must be disposed by calling platformAuthorizer.dispose() before creating a new one.

warning

The application owns the responsibility of returning valid user token through the userAuthorizationDelegate implementation. Whenever there is a change in user using the application, the user token must be refreshed accordingly.

Create Platform Client

The content authorizer is bound to a specific device. The Quickplay client library provides an API to generate a unique PlatformClient instance, which exposes a unique device ID.

import { PlatformClient } from '@quickplay/rn-qp-nxg-player';

const client: PlatformClient = {
/**
* A unique ID for the client device.
*/
id: <UniqueId>,

/**
* The type/category of the client device.
* Possible values:
* - androidmobile
* - androidtablet
* - androidtv
* - androidstb
* - iosmobile
* - iostablet
* - iostv
*/
type: <androidmobile | iosmobile>,
};

Create Content Authorizer

The ContentAuthorization library assists with authorizing an asset for either playback or download. To create an instance of content authorizer one would need platform authorizer, device registration endPoint, content authorization endPoint and a client device.

The ContentAuthorizer expects PlatformAsset which represents a potential playable asset and type of delivery for which authorization is seeked. The delivery type could be streaming or download. Upon successful authorization, PlaybackAsset is obtained, which could be used to play with Quickplay Player.

import { ContentAuthConfig } from '@quickplay/rn-qp-nxg-player';

// Content Authorizer creation
const contentAuthConfig: ContentAuthConfig = {
clientRegistrationEndpointURL: <ClientRegistrationEndpointUrl>,
contentAuthEndpointURL: <contentAuthEndpointURL>,
platformClient: client, // Returned from PlatformClient creation
};

// Returns whether contentAuthorizer is configured or not
if (!(await contentAuthorizer.isConfigured())) {
// Initialize content authorizer
await contentAuthorizer.initWithConfig(contentAuthConfig);
}

// Triggers client registration
try {
await contentAuthorizer.ensureClientRegistration();
} catch (error) {
console.log('Error');
}
note

It is suggested to create contentAuthorizer during start of application and invoke contentAuthorizer.registerDevice ensuring device registration prior to content authorization. If not done, contentAuthorizer would automatically register device prior to the very first content authorization request. Performing device registration at app launch would optimise authorization response time during the first authorization request. There is no limit on contentAuthorizer instance creation, however, it is suggested to use one instance for the complete application session.

warning

A contenAuthorizer is tied to a single device(PlatformClient) and user during its life time. Whenever there is a change with user using the application or change in deviceId(when deviceId was provided while constructing PlatformClient), it is mandatory to re-register the device.

Authorize Playback

The player library is designed with goals to facilitate playback by content url and to provide utmost control for integrators.

A PlatformAsset could be constructed with APIs from ContentAuthorizer providing the following:

  • Content Id: Unique identifier of the content
  • Media Format: HLS | DASH | SmoothStream
  • DRM: Fairplay | Widevine
  • Catalog Type: movie | tvepisode | shortvideo | sportshow | sporthighlight | sportclip | sportevent | sportsliveevent | channel | event
  • Content Type: VOD | Live
import { PlatformAsset, contentAuthorizer, ContentAuthToken  } from '@quickplay/rn-qp-nxg-player';

let contentAuthToken : ContentAuthToken = null;
const platformAsset: PlatformAsset = {
mediaID: <string>;
catalogType: <string>;
consumptionType: <ConsumptionTypeValue>;
mediaType: <MediaTypeValue>;
drmType: <DrmTypeValue>;
}

The created asset - either for streaming or download - must be authorized with the Quickplay platform to obtain a ContentAuthorizationToken.

contentAuthToken = await contentAuthorizer.authorizePlayback(platformAsset)

The ContentAuthorizationToken has content metadata such as content url, license url, licenseToken, mediaFormat and drmType. The asset can be used with Quickplay Player library for playback or download.

Start Playback

A Player instance could be created by supplying player builder properties like contentURL, mediaType, drmScheme, etc to CreatePlayer api . After obtaining contentAuthToken, use its properties to configure the player:

import { PlayerConfig, createPlayer, contentAuthToken  } from '@quickplay/rn-qp-nxg-player';
const playerConfig: PlayerConfig = {
mediaURL: contentAuthToken.contentURL,
drmLicenseURL: contentAuthToken.licenseURL,
drmType: contentAuthToken.drmType,
licenseToken: contentAuthToken.licenseToken,
// ...other properties from contentAuthToken as needed
};

// Pass playerConfig to the Quickplay Player for playback
const player = await createPlayer(playerConfig)