From d9cb5c8f9506c5acc53009576f0ea29e05f48eec Mon Sep 17 00:00:00 2001 From: Matthias Damm Date: Tue, 10 Mar 2020 09:41:53 +0100 Subject: [PATCH] use one token for all SDKs --- controllers/agents.js | 16 ++++++------ controllers/helpers/client-helper.js | 26 ------------------- .../AdministrationController.js | 2 +- public/callcenter/WorkflowController.js | 2 +- 4 files changed, 10 insertions(+), 36 deletions(-) delete mode 100644 controllers/helpers/client-helper.js diff --git a/controllers/agents.js b/controllers/agents.js index da8539b..32428cb 100755 --- a/controllers/agents.js +++ b/controllers/agents.js @@ -8,7 +8,6 @@ const client = twilio( ) const taskrouterHelper = require('./helpers/taskrouter-helper.js') -const clientHelper = require('./helpers/client-helper.js') module.exports.login = function (req, res) { const friendlyName = req.body.worker.friendlyName @@ -56,11 +55,6 @@ var createWorkerTokens = function (configuration, worker, endpoint) { worker.sid ) - /* create a token for Twilio TaskRouter */ - const clientAccessToken = clientHelper.createAccessToken( - worker.friendlyName, configuration.twilio.applicationSid, lifetime - ) - const accessToken = new AccessToken( process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_API_KEY_SID, @@ -79,13 +73,19 @@ var createWorkerTokens = function (configuration, worker, endpoint) { /* grant the access token Twilio Video capabilities */ const videoGrant = new AccessToken.VideoGrant() + /* grant the token Twilio Client capabilities */ + const clientGrant = new AccessToken.VoiceGrant({ + incomingAllow: true, + outgoingApplicationSid: configuration.twilio.applicationSid + }) + accessToken.addGrant(chatGrant) accessToken.addGrant(videoGrant) + accessToken.addGrant(clientGrant) return { worker: workerCapability.toJwt(), - access: accessToken.toJwt(), - voice: clientAccessToken.toJwt() + access: accessToken.toJwt() } } diff --git a/controllers/helpers/client-helper.js b/controllers/helpers/client-helper.js deleted file mode 100644 index 52b87fc..0000000 --- a/controllers/helpers/client-helper.js +++ /dev/null @@ -1,26 +0,0 @@ -const twilio = require('twilio') - -const AccessToken = twilio.jwt.AccessToken - -module.exports.createAccessToken = function (identity, applicationSid, lifetime) { - - const token = new AccessToken( - process.env.TWILIO_ACCOUNT_SID, - process.env.TWILIO_API_KEY_SID, - process.env.TWILIO_API_KEY_SECRET, - { ttl: lifetime } - ) - - token.identity = identity.toLowerCase() - - /* grant the token Twilio Client capabilities */ - const grant = new AccessToken.VoiceGrant({ - incomingAllow: true, - outgoingApplicationSid: applicationSid - }) - - token.addGrant(grant) - - return token -} - diff --git a/public/administration/AdministrationController.js b/public/administration/AdministrationController.js index 6fc3c6d..62f42a3 100755 --- a/public/administration/AdministrationController.js +++ b/public/administration/AdministrationController.js @@ -98,7 +98,7 @@ function AdministrationController ($scope, $http, $log, $q) { /* create attributes which are used for TaskRouter routing */ let attributes = { - contact_uri: 'client:' + $scope.agent.friendlyName.toLowerCase(), + contact_uri: 'client:' + $scope.agent.friendlyName, channels: $scope.agent.channels, team: $scope.agent.team }; diff --git a/public/callcenter/WorkflowController.js b/public/callcenter/WorkflowController.js index cdc6d61..35b3b00 100755 --- a/public/callcenter/WorkflowController.js +++ b/public/callcenter/WorkflowController.js @@ -38,7 +38,7 @@ app.controller('WorkflowController', function ($scope, $rootScope, $http, $inter $scope.initWorker(response.data.tokens.worker); /* initialize Twilio client with token received from the backend */ - $scope.$broadcast('InitializePhone', { token: response.data.tokens.voice }); + $scope.$broadcast('InitializePhone', { token: response.data.tokens.access }); /* initialize Twilio Chat client with token received from the backend */ $scope.$broadcast('InitializeChat', { token: response.data.tokens.access, identity: response.data.worker.friendlyName });