Create your Application, Users, and Tokens
In order to use the Client SDK, there are three things you need to set up before getting started:
- Vonage Application - an Application which contains configuration for the app that you are building.
- Users - Users who are associated with the Vonage Application. It is expected that Users will have a one-to-one mapping with your own authentication system.
- JSON Web Tokens, JWTs - Client SDK uses JWTs for authentication. In order for a user to log in and use the SDK functionality, you need to provide a JWT per user. JWTs contain all the information the Vonage platform needs to authenticate requests, as well as information such as the associated Applications, Users and permissions.
All of these may be created by your backend. If you wish to get started and experience using the SDK straightaway you can also deploy a backend application for use with the Client SDK with the Client SDK Sample Server template. Otherwise, this tutorial will show you how to do so, using the Vonage CLI.
Prerequisites
Make sure you have the following:
- A Vonage account - sign up
- Node.JS and NPM installed
- Install the Vonage CLI.
Create a Vonage Application
You now need to create a Vonage application. In this example you create an application capable of handling both in-app Voice and in-app Messaging use cases.
- First create your project directory if you've not already done so.
- Change into the project directory you've now created.
- Use the following commands to create and configure a Vonage application with Voice and WebRTC capabilities. Replace the webhook URLs with your own. If your platform restricts the inbound traffic it can receive using IP address-ranges you'll need to add the Vonage IP addresses to your allow list. The IP addresses can be fetched programmatically by sending a GET request to
https://api.nexmo.com/ips-v4.
Add Voice Capabilities:
Add RTC Capabilities
The application is then created. A private key file private.key is also created.
Creating an application and application capabilities are covered in detail in the application guide.
Create a User
Create a User who will log in to Vonage Client and participate in the SDK functionality: Conversations, Calls and so on.
Run the following command in your terminal to create a user named Alice:
The user ID is used to perform tasks by the SDK, such as login, starting a call and more.
Generate a User JWT
JWTs are used to authenticate a user into the Client SDK.
To generate a JWT for Alice run the following command (replacing with your information):
The above command defaults the expiry of the JWT to 24 hours. You may change the expiration to a shortened amount of time using the --exp flag.
NOTE: In production apps, it is expected that your backend will expose an endpoint that generates JWT per your client request.