Skip to content

Commit

Permalink
use one token for all SDKs
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Damm committed Mar 10, 2020
1 parent 10630fe commit d9cb5c8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 36 deletions.
16 changes: 8 additions & 8 deletions controllers/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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()
}
}

Expand Down
26 changes: 0 additions & 26 deletions controllers/helpers/client-helper.js

This file was deleted.

2 changes: 1 addition & 1 deletion public/administration/AdministrationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion public/callcenter/WorkflowController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit d9cb5c8

Please sign in to comment.