Skip to content

Instantly share code, notes, and snippets.

@mmcc
Last active January 31, 2019 19:55
Show Gist options
  • Save mmcc/57befda87bc4317e76bd5b6c9546b0d2 to your computer and use it in GitHub Desktop.
Save mmcc/57befda87bc4317e76bd5b6c9546b0d2 to your computer and use it in GitHub Desktop.
Node & Elixir Updates
# These examples assume you have your token id and secret in your Mix config:
# config :mux, token_id: 'your-token-id', token_secret: 'your-token-secret'
# Same as above, first we'll create a token with defaults: 7 day expiration for video
video_token = Mux.Token.sign('your-playback-id')
# https://stream.mux.com/your-playback-id.m3u8?token=#{token}
gif_token = Mux.Token.sign('your-playback-id',
type: :gif,
expiration: 60 * 60 * 3 # 3 hours
params: %{ height: 100 })
# https://image.mux.com/your-playback-id/animated.gif?token=#{token}
// These examples assume you have `MUX_SIGNING_KEY` and
// `MUX_PRIVATE_KEY` environment variables set up.
const Mux = require('@mux/mux-node');
// The tiniest example!
// This creates a token for video playback that is valid for 7 days.
const videoToken = Mux.JWT.sign('your-playback-id');
// https://stream.mux.com/your-playback-id.m3u8?token=${videoToken}
// Now let's make a shorter-lived one for thumbnails that also includes
// what would be query params in a public URL:
const thumbToken = Mux.JWT.sign('your-playback-id', {
type: 'thumbnail',
expiration: 60 * 60 * 3, // 3 hours
params: { height: 100 }
});
// https://image.mux.com/your-playback-id/thumbnail.jpg?token=${thumbToken}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment