Thursday, 13 April 2017

Generated Access Token invalid for Demo Video Application

I am using the sample Video application pulled from GitHub. I am using a node.js server to supply the sample application with the access token. When I use the Twilio Console to generate a video access token and put it in my Node.js server as a literal and return it I am able to run the example application and connect to a room. If I use the sample token generation code in my Node.js server I get 'Invalid Access Token' back in an exception in the onDisconnected method in the Room.Listener.

The following code is what is running in the server to create the access token, I also found a different sample which I tried as well. I have gone back and verified that my data values for the account SID and the API keys are correct. I have a similar method running returning the VoiceGrant access token and that is working, but something about this VideoGrant one is off, I just do not see it.

// ***********************************************************************************
// ***********************************************************************************
// Video Access Token
// ***********************************************************************************
// ***********************************************************************************
var videoCallAccessToken = function(request, response) {
        console.log('/twilio/video/accessToken');
        var accessToken = makeVideoAccessToken();
        response.writeHead(200, {'Content-Type': 'text/plain'});
        response.end(accessToken);
        console.log(accessToken);
};

app.get('/twilio/video/accessToken', videoCallAccessToken);

var makeVideoAccessToken = function() {
        const AccessToken = twilio.AccessToken;
        const VideoGrant = AccessToken.VideoGrant;
        const grant = new VideoGrant({configurationProfileSid: accountData.videoConfigurationProfileSid});
        const accessToken = new AccessToken(accountData.sid, accountData.videoApiSid, accountData.videoApiSecret);
        accessToken.identity = 'ABC123';
        accessToken.addGrant(grant);
        return accessToken.toJwt();
};

FYI...I plan to alter the identity generation, but have not got there yet.

Thanks,



via NinePlanFailed

No comments:

Post a Comment