Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var serviceSid = 'ISxxxxxxxxxxxxx';
var appName = 'HipFlowSlackDockRC';
var identity = 'user@example.com';
var deviceId = 'someiosdeviceid';
var endpointId = appName + ':' + identity + ':' + deviceId;
// Create a "grant" which enables a client to use IPM as a given user,
// on a given device
var ipmGrant = new IpMessagingGrant({
serviceSid: serviceSid,
endpointId: endpointId
});
// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
token.addGrant(ipmGrant);
token.identity = identity;
// Serialize the token to a JWT string
console.log(token.toJwt());
const twilioAccountSid = 'ACxxxxxxxxxx';
const twilioApiKey = 'SKxxxxxxxxxx';
const twilioApiSecret = 'xxxxxxxxxxxx';
// Used specifically for creating Voice tokens
const outgoingApplicationSid = 'APxxxxxxxxxxxxx';
const identity = 'user';
// Create a "grant" which enables a client to use Voice as a given user
const voiceGrant = new VoiceGrant({
outgoingApplicationSid: outgoingApplicationSid,
});
// 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);
token.addGrant(voiceGrant);
token.identity = identity;
// Serialize the token to a JWT string
console.log(token.toJwt());
app.get('/ntsToken/:name', function (request, response) {
var AccessToken = require('twilio').AccessToken;
// Substitute your Twilio AccountSid and ApiKey details
var API_KEY_SID = process.ENV.TWILIO_API_KEY;
var API_KEY_SECRET = process.env.TWILIO_API_KEY_SECRET;
// Create an Access Token
var accessToken = new AccessToken(
twilioCreds.accountSID,
API_KEY_SID,
API_KEY_SECRET
);
// Set the Identity of this token
accessToken.identity = request.params.name;
// Grant access to Conversations
var grant = new AccessToken.ConversationsGrant();
grant.configurationProfileSid = process.env.TWILIO_PROFILE_SID;
accessToken.addGrant(grant);
// Serialize the token as a JWT
var jwt = accessToken.toJwt();
console.log(jwt);
app.get('/token', function(request, response) {
var identity = randomUsername();
// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY,
process.env.TWILIO_API_SECRET
);
//assign the generated identity to the token
token.identity = identity;
//grant the access token Twilio Video capabilities
var grant = new VideoGrant();
grant.configurationProfileSid = process.env.TWILIO_CONFIGURATION_SID;
token.addGrant(grant);
// Serialize the token to a JWT string and include it in a JSON response
response.send({
identity: identity,
var getToken = function(request, response) {
log.debug('Generating Twilio token');
var identity = request.query.identity;
// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY,
process.env.TWILIO_API_SECRET
);
// Assign the generated identity to the token
token.identity = identity;
//grant the access token Twilio Video capabilities
var grant = new ConversationsGrant();
grant.configurationProfileSid = process.env.TWILIO_CONFIGURATION_SID;
token.addGrant(grant);
// Serialize the token to a JWT string and include it in a JSON response
response.send({
identity: identity,
app.get('/token', function(request, response) {
var identity = randomUsername();
// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY,
process.env.TWILIO_API_SECRET
);
//assign the generated identity to the token
token.identity = identity;
//grant access to Video
var grant = new VideoGrant();
grant.configurationProfileSid = process.env.TWILIO_CONFIGURATION_SID;
token.addGrant(grant);
// Serialize the token to a JWT string and include it in a JSON response
response.send({
identity: identity,
var getToken = function(request, response) {
log.debug('Generating Twilio token');
var identity = request.query.identity;
// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY,
process.env.TWILIO_API_SECRET
);
// Assign the generated identity to the token
token.identity = identity;
//grant the access token Twilio Video capabilities
var grant = new ConversationsGrant();
grant.configurationProfileSid = process.env.TWILIO_CONFIGURATION_SID;
token.addGrant(grant);
// Serialize the token to a JWT string and include it in a JSON response
response.send({
identity: identity,
var appName = this.botConfig.apiaiAccessToken;
var deviceId = "server";
// Create a unique ID for the client on their current device
var endpointId = "TwilioChat:" + this.botConfig.botIdentity + ":browser";
// Create a "grant" which enables a client to use IPM as a given user,
// on a given device
var ipmGrant = new IpMessagingGrant({
serviceSid: this.botConfig.serviceSid,
endpointId: endpointId
});
// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(
this.botConfig.accountSid,
this.botConfig.signingKeySid,
this.botConfig.signingKeySecret
);
token.addGrant(ipmGrant);
token.identity = this.botConfig.botIdentity;
resolve(token.toJwt());
});
}
function createToken(identity, options) {
options = Object.assign({}, defaults, options);
const {
accountSid,
apiKeySecret,
apiKeySid,
configurationProfileSid,
ttl
} = options;
const accessToken = new AccessToken(
accountSid,
apiKeySid,
apiKeySecret,
{ ttl });
accessToken.identity = identity;
let grant = options.grant;
switch (grant) {
case 'conversations':
grant = new AccessToken.ConversationsGrant({
identity,
configurationProfileSid
});
break;
case 'video':
client.verifyIdToken(body.tokenId, process.env.GOOGLE_CLIENT_ID, (e, login) => {
const payload = login.getPayload();
const userId = payload.sub;
if (userId === body.googleId) {
const token = new AccessToken(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY,
process.env.TWILIO_API_SECRET
);
token.identity = body.googleId;
const grant = new VideoGrant();
grant.configurationProfileSid = process.env.TWILIO_CONFIGURATION_SID;
token.addGrant(grant);
response.send({
identity: body.googleId,
token: token.toJwt(),
});
} else {