问题
I am using twilio voice call and it is working properly. But the twilio jwt token ends every hour. For this, the user has to refresh the page every hour. My question is how to extend the token time in nodejs.
I am using this code to generate a token
var twilio = require('twilio');
var client = twilio(config.accountSid, config.authToken);
const ClientCapability = twilio.jwt.ClientCapability;
app.get('/token', (request, response) => {
const capability = new ClientCapability({
accountSid: config.accountSid,
authToken: config.authToken
});
capability.addScope(
new ClientCapability.OutgoingClientScope({
applicationSid: config.applicationSid
})
);
const token = capability.generateToken();
// Include token in a JSON response
response.send({
token: token,
});
});
Thanks
回答1:
From the documentation:
https://www.twilio.com/docs/voice/client/capability-tokens
Here, we generate a token that's only valid for ten minutes. The expires argument expects time in seconds.
capability = ClientCapabilityToken(account_sid, auth_token, ttl=600)
print(capability.to_jwt())
回答2:
Twilio developer evangelist here.
Access tokens do have limited lifespans. As Ankush answered, you can set a different ttl up to 24 hours.
Better yet is to use the Twilio Access Manager. It is available as part of twilio-common for JavaScript, or the Access Manager package on iOS and Android.
The AccessManager will fire off two events that you can hook into. Firstly, when a token is near expiry, it will fire a token expired event. Hook into that event and when you receive it, generate a new token from your server. You can then set that new token in the AccessManager.
Once that token is set, the AccessManager will fire a token updated event which you can listen for and update the token in your Twilio Voice Client (or Chat, Video or Sync client, depending on what you are using).
To see how to download, install and use the Access Manager in detail for each of these platforms, take a look at the Access Token life cycle and Access Manager documentation.
Let me know if that helps at all.
来源:https://stackoverflow.com/questions/51605909/twilio-jwt-token-expired