Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.get('/token', function(req, res) {
// put your Twilio API credentials here
var accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var authToken = "your_auth_token";
// put your Twilio Application Sid here
var appSid = "APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var capability = new twilio.Capability(accountSid, authToken);
capability.allowClientOutgoing(appSid);
capability.allowClientIncoming(req.body.ClientName);
var token = capability.generate();
res.set('Content-Type', 'application/jwt')
res.send(token);
});
app.get('/token', function(req, res) {
// put your Twilio API credentials here
var accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var authToken = "your_auth_token";
var capability = new twilio.Capability(accountSid, authToken);
capability.allowClientIncoming("jenny");
var token = capability.generate();
res.set('Content-Type', 'application/jwt')
res.send(token);
});
app.get('/token', function(req, res) {
// put your Twilio API credentials here
var accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var authToken = "your_auth_token";
// put your Twilio Application Sid here
var appSid = "APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var capability = new twilio.Capability(accountSid, authToken);
capability.allowClientOutgoing(appSid);
var token = capability.generate();
res.set('Content-Type', 'application/jwt')
res.send(token);
});
function makeIncomingCapabilityToken(incomingClientName) {
var capability = new twilio.Capability(ACCOUNT_SID, AUTH_TOKEN);
capability.allowClientIncoming(incomingClientName);
return capability.generate();
}
function getCapabilityToken(incomingClientName, outgoingAppSid, outgoingParameters, errorCallback, successCallback) {
var capability = new twilio.Capability(ACCOUNT_SID, AUTH_TOKEN);
if (incomingClientName)
capability.allowClientIncoming(incomingClientName);
if (outgoingAppSid) {
if (outgoingParameters)
capability.allowClientOutgoing(outgoingAppSid, util.fromURLFormEncoded(outgoingParameters));
else
capability.allowClientOutgoing(outgoingAppSid);
}
var capabilityTokenString = capability.generate();
try {
var capabilityToken = new CapabilityToken(capabilityTokenString);
} catch (e) {
return errorCallback(e);
}
successCallback(capabilityToken);
}
function makeOutgoingCapabilityToken(outgoingParameters) {
var capability = new twilio.Capability(ACCOUNT_SID, AUTH_TOKEN);
capability.allowClientOutgoing(APP_SID, outgoingParameters || null);
return capability.generate();
}
function getTwilioClientToken(email, credentials) {
var capability = new twilio.Capability(credentials.accountSid, credentials.authToken)
capability.allowClientIncoming(emailToClientName(email))
capability.allowClientOutgoing(credentials.outgoingApplicationSid)
return(capability.generate())
}
response.end(twiml.toString());
}
else if (hash.pathname === '/random') {
var client = new twilio.RestClient(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
client.messages.list({'To': 'yyy'}, function(err, data) {
random = data.messages[Math.floor(Math.random() * data.messages.length - 1)];
var twiml = new twilio.TwimlResponse();
twiml.dial({'callerId': 'yyy'}, function() {
this.number(random.from);
});
response.writeHead(200, {'content-type': 'text/xml'});
response.end(twiml.toString());
});
}
else if (hash.pathname === '/token') {
var capability = new twilio.Capability(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
capability.allowClientOutgoing('APxxx');
response.end(capability.generate());
}
else {
file.serve(request, response);
}
}).resume();
}).listen(process.env.PORT || 3000);
function createCapability(user) {
var capability = new Twilio.Capability(config.twilio.sid, config.twilio.token);
capability.allowClientOutgoing(config.twilio.app);
capability.allowClientIncoming(user.username);
return capability.generate();
}