Twilio JWT Token expired

我的梦境 提交于 2019-12-13 07:49:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!