Twilio 语音 - 无效的访问令牌签名
Twilio Voice - Invalid Access Token Signature
我正在使用 twilio. When I validate the token in https://jwt.io with the secret, it says the signature is verified. But I keep getting the below error message in twilio voice quick start iOS App 提供的 NodeJS 服务器代码创建访问令牌。
{"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
此处为 Twilio 开发人员布道师。
虽然您的令牌看起来一切正常,但结果 there was an incident recently to do with API key creation。因此,您的 API 密钥在 Twilio 方面可能已损坏。
最好的办法是回到您的 Twilio console and create a new API key and secret 并尝试使用它们。
让我知道进展如何。
我正在使用 twilio. When I validate the token in https://jwt.io with the secret, it says the signature is verified. But I keep getting the below error message in twilio voice quick start iOS App 提供的 NodeJS 服务器代码创建访问令牌。
{"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
此处为 Twilio 开发人员布道师。
虽然您的令牌看起来一切正常,但结果 there was an incident recently to do with API key creation。因此,您的 API 密钥在 Twilio 方面可能已损坏。
最好的办法是回到您的 Twilio console and create a new API key and secret 并尝试使用它们。
让我知道进展如何。