Welcome to One Dev Minute! This series is hosted on the Vonage Dev YouTube channel. The goal of this video series is to share knowledge in a bite-sized manner.
In this video, Amanda Cavallaro, our Developer Advocate, shows you how the token roles allow you to identify users and change the permission roles using the Vonage Video API.
Transcript
Hi! This is Amanda Cavallaro, a Developer Advocate at Vonage, and today I'll talk about generating and assigning token roles.
To authenticate a user connecting to a video API session we must use a unique authentication key called "token".
There are three possible token roles: subscriber, publisher, and moderator.
Let's generate a token using the video API Node.js server-side library.
We first install Opentok from the terminal. In your coding editor, you set the constants with the API key and the API secret that you receive when you sign up to use the video API.
You can create or use an existing session ID. Next, we call the generateToken method that will return a token in the string format.
You can generate tokens for clients to use when connecting to the session. In this example, we are creating a username "Amanda" of role "publisher".
The options parameter is an optional object used to set the role, expiry time, and connection data of the token. We then add the token options to the generated token, run Node and the name of the file we created and in your terminal, you can see your token.
There are a number of things you can do with your generated token depending on its role. You have additional permissions if you receive a moderator token. You can, for instance, disconnect, mute other users, or even stop publishing their streams.
In this video, you saw how to generate and design a token. You can learn further from the links below!
Links
Join the Vonage Developer Community Slack