0

I am attempting to follow this tutorial: https://www.youtube.com/watch?v=5lrdYBLEk60 and am getting Invalid Access Token - Code: 20101 returned when I follow everything to a tee. I changed nothing in the VideoQuickStart provided, other than adding my Twilio function link with identity: https://carnelian-chinook-9032.twil.io/video-token?identity=doug

Code for function (same as video linked):

exports.handler = function(context, event, callback) {
    const AccessToken = Twilio.jwt.AccessToken;
    const VideoGrant = AccessToken.VideoGrant;

    const token = new AccessToken(context.ACCOUNT_SID, context.API_KEY, context.API_SECRET);
    token.identity = event.identity;

    const videoGrant = new VideoGrant({
        room: 'TestingRoom'
    });

    token.addGrant(videoGrant);

    callback(null, { token: token.toJwt() });
};

Beginning of ViewController.swift from VideoQuickStart example

import UIKit

import TwilioVideo

class ViewController: UIViewController {

    // MARK: View Controller Members

    // Configure access token manually for testing, if desired! Create one manually in the console
    // at https://www.twilio.com/console/video/runtime/testing-tools
    var accessToken = "TWILIO_ACCESS_TOKEN"

    // Configure remote URL to fetch token from
    var tokenUrl = "https://carnelian-chinook-9032.twil.io/video-token?identity=doug"

    // Video SDK components
    var room: TVIRoom?
    var camera: TVICameraSource?
    var localVideoTrack: TVILocalVideoTrack?
    var localAudioTrack: TVILocalAudioTrack?
    var remoteParticipant: TVIRemoteParticipant?
    var remoteView: TVIVideoView?

    // MARK: UI Element Outlets and handles

    // `TVIVideoView` created from a storyboard
    @IBOutlet weak var previewView: TVIVideoView!

    @IBOutlet weak var connectButton: UIButton!
    @IBOutlet weak var disconnectButton: UIButton!
    @IBOutlet weak var messageLabel: UILabel!
    @IBOutlet weak var roomTextField: UITextField!
    @IBOutlet weak var roomLine: UIView!
    @IBOutlet weak var roomLabel: UILabel!
    @IBOutlet weak var micButton: UIButton!

    // MARK: UIViewController
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "QuickStart"
....

Anyone know what I can try for this? Or if they can follow the tutorial and it works on their end? Maybe the tutorial is a bit outdated? Maybe I need to enable something on my account? Anything helps, thanks!

Repo used for example: https://github.com/twilio/video-quickstart-ios

1 Answer 1

1

Twilio developer evangelist here.

The issue here is that you are using Test Credentials to create your token. Twilio test credentials are only useful for testing API responses to requests to send a message, buy a number or make a phone call without actually triggering the action.

Switch out for your real credentials and everything should work just fine.

Edit

Using the quickstart that you linked to, the access token is requested by this code which doesn't parse the JSON and look for the token.

If you return just the token as a string payload instead of a JSON payload, then this should work. To update the function, change the callback to:

callback(null, token.toJwt()); 
Sign up to request clarification or add additional context in comments.

8 Comments

Okay that's kinda what I was thinking, but as the tutorial shows under Functions > Config, you check the box for Enable ACCOUNT_SID and AUTH_TOKEN so that they can be grabbed from context. How do I have that grab the real credentials?
Have you overridden the ACCOUNT_SID and AUTH_TOKEN in the config section of Functions?
No, should I pass the real credentials explicitly in Config > Env Variables?
No, you shouldn't have to pass them in the env variables. That's why I wondered if you had overridden them in there. I can't see another reason that your account sid would be set to your test credentials. I'm checking with the team to see what has happened here.
Can you double check whether you have set ACCOUNT_SID in Config > Env Variables and delete it if you have, please?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.