0
votes

I am using Twilio's latest SDK they released on CocoaPods as of today. I am trying to implement VOIP feature to my app with Twilio Programmable Voice. My backend is .net which also uses the latest release of Twilio Helper Library for C#.

My client code looks like:

fetchAccessToken { (accessToken: String) in

        TwilioVoice.register(withAccessToken: accessToken, deviceToken: deviceToken) { (error) in
            if let error = error {
                NSLog("An error occurred while registering: \(error.localizedDescription)")
            }
            else {
                NSLog("Successfully registered for VoIP push notifications.")
            }
        }

    }

What I get in the console is as following:

voipTestWithTwilio[2431:517236] [ERROR TwilioVoice] Inside register:deviceToken:completion:, failed to register for Twilio push notifications. Error:Invalid access token signature
voipTestWithTwilio[2431:517236] An error occurred while registering: Invalid access token signature

This is the C# code that actually creates the token:

var grant = new VoiceGrant
            {
                OutgoingApplicationSid = outgoingApplicationSid
            };

            var grants = new HashSet<IGrant> { { grant } };

            var token = new Token(
                accountSid: accountSid,
                signingKeySid: apiKey,
                secret: apiSecret,
                identity: identity,
                grants: grants
            );
            return token.ToJwt();

I have been looking for the issue on the internet, nothing helped so far. I have tried contacting them but have not got any response back. I also tried creating new api keys and even a new project for a couple times on Twilio. Can anybody say something about the issue?

UPDATE

I added push notification sid to VoiceGrant and now I’m getting 403 Forbidden.

On Twilio error codes page it is explained as: “The expiration time provided in the Access Token exceeds the maximum duration allowed.” which is definitely not my case. However, I tried passing expiration parameter in Token constructor with various values which didn’t change the result.

The problem is still persisting.

1

1 Answers

2
votes

I solved the issue. It was because my server returned the token with quotation mark.

I remember print(token)'ing on client (iOS) to see whether there is encoding issue or something and all I see was a proper token between quotation marks. Since token is a string value, I didn't pay attention to quotation part of it. That's where I was wrong.