Twilio语音 - 无效的访问令牌签名

时间:2017-07-07 09:26:28

标签: twilio jwt twilio-api twilio-click-to-call

我正在使用twilio提供的NodeJS服务器代码创建访问令牌。当我使用秘密验证https://jwt.io中的令牌时,它表示签名已经过验证。但我一直在twilio voice quick start iOS App中收到以下错误消息。

{"code":20107,"message":"Invalid Access Token signature"}

这是我在twilio提供的Node.JS中的令牌生成代码。有人可以指导我在哪里出错。

const AccessToken = require('twilio').jwt.AccessToken;
const VoiceGrant = AccessToken.VoiceGrant;

// Used when generating any kind of tokens
const twilioAccountSid = 'ACxxxxxxxxxx';
const twilioApiKey = 'SKxxxxxxxxxx';
const twilioApiSecret = 'xxxxxxxxxxxx';

// Used specifically for creating Voice tokens
const outgoingApplicationSid = 'APxxxxxxxxxxxxx';
const identity = 'user';

// Create a "grant" which enables a client to use Voice as a given user
const voiceGrant = new VoiceGrant({
    outgoingApplicationSid: outgoingApplicationSid
});

// Create an access token which we will sign and return to the client,
// containing the grant we just created
const token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
token.addGrant(voiceGrant);
token.identity = identity;

// Serialize the token to a JWT string
console.log(token.toJwt());

编辑: 创建JWT访问令牌的示例。

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTSzRkMjg2MWQ0YjQ4MDljZTNiNjUyOTRjNWMwZTFjNmI3LTE0OTk0Mjg4NDgiLCJncmFudHMiOnsiaWRlbnRpdHkiOiJ1c2VyIiwidm9pY2UiOnsib3V0Z29pbmciOnsiYXBwbGljYXRpb25fc2lkIjoiQVBiY2I5MDMwMDdhZTRmZjllZmMxNWYzY2VlODAzMzA4NSJ9fX0sImlhdCI6MTQ5OTQyODg0OCwiZXhwIjoxNDk5NDMyNDQ4LCJpc3MiOiJTSzRkMjg2MWQ0YjQ4MDljZTNiNjUyOTRjNWMwZTFjNmI3Iiwic3ViIjoiQUM5NTQ4ZDc5YTRjNzU5YzQwNzAxYThkMDExMWIzNDU0MyJ9.uw5PO3mYm1kdMyCageMMZG40_vU9z7czDrZj7h8N7_Y

1 个答案:

答案 0 :(得分:1)

Twilio开发者传道者在这里。

虽然您的令牌看起来一切正常但事实证明there was an incident recently to do with API key creation。因此,您的API密钥可能在Twilio方面已损坏。

最好的办法是回到你的Twilio console and create a new API key and secret并尝试这些。

让我知道这是怎么回事。