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

问题描述:

我使用由twilio提供的NodeJS服务器代码创建访问令牌。当我用密码验证https://jwt.io中的令牌时,它表示签名已被验证。但我不断收到twilio voice quick start iOS App中的以下错误消息。Twilio语音 - 访问令牌签名无效

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

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

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 
+0

你能分享(通过编辑你的问题)一个你正在创建的JWT访问令牌的例子吗?谢谢 – philnash

+0

@philnash添加了一个我正在创建的示例JWT访问令牌。 – kurrodu

+0

我在猜测,但可以确保在创建API时使用API​​密钥随附的API密钥。如果您无法获得您在此令牌中使用的API密钥的API密钥,那么您需要创建另一对并使用它们。您不应该使用您帐户的身份验证令牌。 – philnash

Twilio开发者传道这里。

虽然一切看起来正确与您的令牌,事实证明there was an incident recently to do with API key creation。所以,你的API密钥可能在Twilio身上被破坏。

要做的最好的事情是回到并尝试那些。

让我知道那是怎么回事。