2017-07-07 28 views
0

我使用由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

回答