Created
February 9, 2018 06:36
-
-
Save ktoraskartwilio/513e3c5f317393315938c86a6246e6fe to your computer and use it in GitHub Desktop.
Node.js Token Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Twilio Video Token Generation | |
* | |
* Pre-requisites | |
* - Create an API Key (https://www.twilio.com/console/runtime/api-keys) | |
*/ | |
exports.handler = function(context, event, callback) { | |
const AccessToken = Twilio.jwt.AccessToken; | |
const VideoGrant = AccessToken.VideoGrant; | |
// make sure you enable ACCOUNT_SID and AUTH_TOKEN in Functions/Configuration | |
const ACCOUNT_SID = context.ACCOUNT_SID; | |
const API_KEY = context.TWILIO_API_KEY; | |
const API_SECRET = context.TWILIO_API_SECRET; | |
const IDENTITY = 'Hacker Owl'; | |
const accessToken = new AccessToken( | |
ACCOUNT_SID, | |
API_KEY, | |
API_SECRET | |
); | |
const videoGrant = new VideoGrant(); | |
accessToken.addGrant(videoGrant); | |
accessToken.identity = IDENTITY; | |
callback(null, { token: accessToken.toJwt() }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment