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

douglasrcjames
  • 1,133
  • 3
  • 17
  • 37

1 Answers1

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()); 
philnash
  • 70,667
  • 10
  • 60
  • 88
  • 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? – douglasrcjames Sep 25 '19 at 23:04
  • Have you overridden the ACCOUNT_SID and AUTH_TOKEN in the config section of Functions? – philnash Sep 25 '19 at 23:06
  • No, should I pass the real credentials explicitly in Config > Env Variables? – douglasrcjames Sep 25 '19 at 23:09
  • 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. – philnash Sep 25 '19 at 23:20
  • Can you double check whether you have set `ACCOUNT_SID` in Config > Env Variables and delete it if you have, please? – philnash Sep 25 '19 at 23:27
  • Yes, so I have passed only the API_KEY and API_SECRET in the environment variables, which I got from Programmable Video > Tools > API Keys . Standard key type, API_KEY = SID, API_SECRET = secret . I also have `Enable ACCOUNT_SID and AUTH_TOKEN` checked. – douglasrcjames Sep 25 '19 at 23:34
  • I also created a new trial account to make sure it wasn't my previous account, still have same issues after following the tutorial exactly. – douglasrcjames Sep 25 '19 at 23:37
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/199984/discussion-between-dangerdoug-and-philnash). – douglasrcjames Sep 25 '19 at 23:49