I am creating an access token using the NodeJS server code provided by 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.
{"code":20107,"message":"Invalid Access Token signature"}
Here is my token generation code in Node.JS as provided by twilio. Could someone please guide me where I am going wrong.
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());
Edit: example of JWT access token created.
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTSzRkMjg2MWQ0YjQ4MDljZTNiNjUyOTRjNWMwZTFjNmI3LTE0OTk0Mjg4NDgiLCJncmFudHMiOnsiaWRlbnRpdHkiOiJ1c2VyIiwidm9pY2UiOnsib3V0Z29pbmciOnsiYXBwbGljYXRpb25fc2lkIjoiQVBiY2I5MDMwMDdhZTRmZjllZmMxNWYzY2VlODAzMzA4NSJ9fX0sImlhdCI6MTQ5OTQyODg0OCwiZXhwIjoxNDk5NDMyNDQ4LCJpc3MiOiJTSzRkMjg2MWQ0YjQ4MDljZTNiNjUyOTRjNWMwZTFjNmI3Iiwic3ViIjoiQUM5NTQ4ZDc5YTRjNzU5YzQwNzAxYThkMDExMWIzNDU0MyJ9.uw5PO3mYm1kdMyCageMMZG40_vU9z7czDrZj7h8N7_Y