Twilio JWT 令牌已过期 [英] Twilio JWT Token expired

查看:48
本文介绍了Twilio JWT 令牌已过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 twilio 语音通话,它工作正常.但是 twilio jwt 令牌每小时结束一次.为此,用户必须每小时刷新一次页面.我的问题是如何在nodejs中延长token时间.

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,
    });
});

谢谢

推荐答案

来自文档:

https://www.twilio.com/docs/voice/client/capability-tokens

在这里,我们生成一个仅在十分钟内有效的令牌.expires 参数需要以秒为单位的时间.

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())

这篇关于Twilio JWT 令牌已过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆