jwt - 功能 token 无效或丢失 Twilio

标签 jwt twilio twilio-php twilio-click-to-call twilio-programmable-voice

我已集成 Twilio 可编程语音。现在我正在尝试让客户端从浏览器进行调用,并使用 Twilio JS Client 接收对浏览器的调用。当我尝试调用电话时,它说。

message: "Capability token is not valid or missing."

我也搜索了互联网和 Twilio 文档,但没有任何帮助。这是我的代码。

查看

<button onclick="callCustomer('{{ '+xxxxxxxx' }}')" type="button" class="btn btn-primary btn-lg call-customer-button">
     Call customer
</button>

Controller

public function newToken(Request $request) {
    // Required for all Twilio access tokens
    $twilioAccountSid = 'ACxxxxxxxxx';
    $twilioApiKey = 'SKxxxxxxxxxxx';
    $twilioApiSecret = 'xxxxxx';

    $outgoingApplicationSid = 'APxxxxxxxxxxx';
    $identity = "Jhon_Doe";

    $token = new AccessToken(
            $twilioAccountSid, $twilioApiKey, $twilioApiSecret, 3600, $identity
    );

    $voiceGrant = new VoiceGrant();
    $voiceGrant->setOutgoingApplicationSid($outgoingApplicationSid);

    $voiceGrant->setIncomingAllow(true);

    $token->addGrant($voiceGrant);

    return $token->toJWT();
}

JS

function callCustomer(phoneNumber) {
    $.get("/token", {forPage: window.location.pathname}, function (data) {
        console.log(data);
        const device = new Twilio.Device();
        device.setup(data);
        
        var params = {"phoneNumber": phoneNumber};
        device.connect(params);
    });
}

我尝试从 jwt.io 调试工具调试我的 token ,它显示:

Invalid Signature.

我确信我错过了一些东西,但不知道是什么。任何帮助或提示将不胜感激。

最佳答案

我已经弄清楚了,只是发布答案以供将来引用。问题出在 twilio js 版本上。我已经包含了导致问题的旧版本。迄今为止的最新版本是版本:1.13。此版本中已弃用功能 token ,现在使用访问 token 。

关于jwt - 功能 token 无效或丢失 Twilio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65420708/

相关文章:

android - Twilio 安卓 : Issue in joining a channel : "Member already exists"

php - 无法让 twilio 收集工作

reactjs - 我需要在客户端检查 JWT 到期时间吗?

azure - 内置注册/登录策略 Azure B2C 声明的默认值

javascript - 我如何可靠地获取特定参与者离开(和加入)twilio 房间的时间戳?

twilio - 获取特定号码的语音定价时出错

PHP - 如何在 Composer 命名空间环境中访问 Twilio

node.js - 使用 twilio 调用电话

node.js - 使用 Google Cloud Key Management Service 签署 JSON Web Tokens

spring-security - 微服务到微服务调用,来自队列消息的授权