Reference Source Test
public class | source

JWT

JWT - Signed URL token generation helpers

Example:

const Mux = require('@mux/mux-node');

const token = Mux.JWT.sign('some-playback-id', { keyId: 'your key id', keySecret: 'your key secret' })

Static Method Summary

Static Public Methods
public static

decode(token: string): Object

Decodes an existing token.

public static

sign(playbackId: string, options: Object): string

Creates a new token to be used with a signed playback ID

Static Public Methods

public static decode(token: string): Object source

Decodes an existing token.

Note: This does not cryptographically verify the token signature, it simply decodes the values.

Params:

NameTypeAttributeDescription
token string

The token you'd like to decode.

Return:

Object

If the token could be decoded, it returns the decoded token object

Example:

const Mux = require('@mux/mux-node');

const token = Mux.JWT.sign('some-playback-id', { keyId: 'your key id', keySecret: 'your key secret' });
const decoded = Mux.JWT.decode(token);
// decoded will be the raw decoded JWT, so you'll see keys like `aud`, `exp`, etc.

public static sign(playbackId: string, options: Object): string source

Creates a new token to be used with a signed playback ID

Params:

NameTypeAttributeDescription
playbackId string

The Playback ID (of type 'signed') that you'd like to generate a token for.

options Object

Configuration options to use when creating the token

options.keyId string
  • optional

The signing key ID to use. If not specified, process.env.MUX_SIGNING_KEY is attempted

options.keySecret string
  • optional

The signing key secret. If not specified, process.env.MUX_PRIVATE_KEY is used.

options.type string
  • optional
  • default: video

Type of token this will be. Valid types are video, thumbnail, gif, or storyboard

options.expiration string
  • optional
  • default: 7d

Length of time for the token to be valid.

options.params Object
  • optional

Any additional query params you'd use with a public url. For example, with a thumbnail this would be values such as time.

Return:

string

Returns a token to be used with a signed URL.

Example:

const Mux = require('@mux/mux-node');

const token = Mux.JWT.sign('some-playback-id', { keyId: 'your key id', keySecret: 'your key secret' });
// Now you can use the token in a url: `https://stream.mux.com/some-playback-id.m3u8?token=${token}`