Skip to content

Commit a73dcda

Browse files
philcluffjsanford8
authored andcommitted
First pass of adding DRM license signing support. Also fixes some documentation around other signing functions.
1 parent e56734f commit a73dcda

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/resources/jwt.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,32 @@ export class Jwt extends APIResource {
3535
}
3636

3737
/**
38-
* Creates a new token to be used with a signed statistics request
38+
* Creates a new token for a license for playing back DRM'd video content
39+
*/
40+
async signDrmLicense(
41+
playbackId: string,
42+
config: MuxJWTSignOptions<keyof typeof TypeClaim> = {},
43+
): Promise<string> {
44+
const claim = TypeClaim[config.type ?? 'drm_license'];
45+
if (!claim) {
46+
throw new Error(`Invalid signature type: ${config.type}; Expected one of ${Object.keys(TypeClaim)}`);
47+
}
48+
49+
const tokenOptions: SignOptions = {
50+
keyid: jwt.getSigningKey(this._client, config),
51+
subject: playbackId,
52+
audience: claim,
53+
expiresIn: config.expiration ?? '7d',
54+
noTimestamp: true,
55+
algorithm: 'RS256',
56+
};
57+
58+
return jwt.sign(config.params ?? {}, await jwt.getPrivateKey(this._client, config), tokenOptions);
59+
}
60+
61+
/**
62+
* Creates a new token to be used with a space
63+
* @deprecated Mux Real-Time Video (spaces) has been shut down. This function will be removed in the next major version.
3964
*/
4065
async signSpaceId(spaceId: string, config: MuxJWTSignOptions<never> = {}): Promise<string> {
4166
const tokenOptions: SignOptions = {
@@ -51,7 +76,7 @@ export class Jwt extends APIResource {
5176
}
5277

5378
/**
54-
* Creates a new token to be used with a signed playback ID
79+
* Creates a new token to be used with a signed statistics request
5580
*/
5681
async signViewerCounts(
5782
id: string,

src/util/jwt-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export enum TypeClaim {
4949
gif = 'g',
5050
storyboard = 's',
5151
stats = 'playback_id',
52+
drm_license = 'l',
5253
}
5354

5455
export enum DataTypeClaim {

0 commit comments

Comments
 (0)