Skip to content

Instantly share code, notes, and snippets.

@abundis29
Created January 29, 2024 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abundis29/a0d2fc3d4210938f561374f962239afd to your computer and use it in GitHub Desktop.
Save abundis29/a0d2fc3d4210938f561374f962239afd to your computer and use it in GitHub Desktop.
const AccessToken = require('twilio').jwt.AccessToken;
const VoiceGrant = AccessToken.VoiceGrant;
// Used when generating any kind of tokens
// To set up environmental variables, see http://twil.io/secure
// Used specifically for creating Voice tokens
const outgoingApplicationSid = 'APd03584f63d77249726a31e44e315398';
const identity = 'user';
// Create a "grant" which enables a client to use Voice as a given user
const voiceGrant = new VoiceGrant({
outgoingApplicationSid: outgoingApplicationSid,
incomingAllow: true, // Optional: add to allow incoming calls
});
console.log(voiceGrant)
// Create an access token which we will sign and return to the client,
// containing the grant we just created
const token = new AccessToken(
twilioAccountSid,
twilioApiKey,
twilioApiSecret,
{identity: identity}
);
token.addGrant(voiceGrant);
// Serialize the token to a JWT string
console.log(token.toJwt());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment