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 without any implementation of your backend, 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.

Check out Getting Started with Vonage CLI for more information on how to install and configure the 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.

  1. First create your project directory if you've not already done so.

  2. Change into the project directory you've now created.

  3. Use the following command to create 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.

vonage apps create 'Your application'✅ Creating ApplicationSaving private key ... Done!Application createdName: Your applicationApplication ID: 00000000-0000-0000-0000-000000000000Improve AI: OffPrivate/Public Key: SetCapabilities: None Enabled
  1. Once you have the application, you then need to add the voice and rtc capabilities:
vonage apps capabilities update 00000000-0000-0000-0000-000000000000 voice \ --voice-answer-url='https://example.com/webhooks/voice/answer' \ --voice-event-url='https://example.com/webhooks/voice/event' \ --voice-fallback-url='https://example.com/webhooks/voice/fallback'✅ Fetching Application✅ Adding voice capability to application 00000000-0000-0000-0000-000000000000Name: Your applicationApplication ID: 00000000-0000-0000-0000-000000000000Improve AI: OffPrivate/Public Key: SetCapabilities: VOICE: Uses Signed callbacks: On Conversation TTL: 41 hours Leg Persistence Time: 6 days Event URL: [POST] https://example.com/webhooks/voice/event Answer URL: [POST] https://example.com/webhooks/voice/answer Fallback URL: [POST] https://example.com/webhooks/voice/fallback
vonage apps capabilities update 00000000-0000-0000-0000-000000000000 rtc \ --rtc-event-url='https://example.com/webhooks/rtc/fallback'✅ Fetching Application✅ Adding rtc capability to application 00000000-0000-0000-0000-000000000000Name: Your applicationApplication ID: 00000000-0000-0000-0000-000000000000Improve AI: OffPrivate/Public Key: SetCapabilities: RTC: Event URL: [POST] https://example.com/webhooks/voice/rtc Uses Signed callbacks: Off

The application is then created and has the needed capabilities. Creating an application and application capabilities are covered in detail in the documentation.

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:

vonage users create \ --name='Alice'✅ Creating UserUser ID: USR-00000000-0000-0000-0000-000000000000Name: AliceDisplay Name: Not SetImage URL: Not SetTime to Live: Not SetChannels: None Set

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:

vonage jwt create \--app-id='00000000-0000-0000-0000-000000000000' \--private-key=./private.key--sub='Alice' \--acl='{"paths":{"/*/rtc/**":{},"/*/users/**":{},"/*/conversations/**":{},"/*/sessions/**":{},"/*/devices/**":{},"/*/image/**":{},"/*/media/**":{},"/*/applications/**":{},"/*/push/**":{},"/*/knocking/**":{},"/*/legs/**":{}}}'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2wiOnsicGF0aHMiOnsiLyovcnRjLyoqIjp7fSwiLyovdXNlcnMvKioiOnt9LCIvKi9jb252ZXJzYXRpb25zLyoqIjp7fSwiLyovc2Vzc2lvbnMvKioiOnt9LCIvKi9kZXZpY2VzLyoqIjp7fSwiLyovaW1hZ2UvKioiOnt9LCIvKi9tZWRpYS8qKiI6e30sIi8qL2FwcGxpY2F0aW9ucy8qKiI6e30sIi8qL3B1c2gvKioiOnt9LCIvKi9rbm9ja2luZy8qKiI6e30sIi8qL2xlZ3MvKioiOnt9fX0sImV4cCI6MTczNjI4MzQ1Miwic3ViIjoibXktdXNlci1uYW1lIiwianRpIjoiM2NiNjBhMzktYWRkNC00NjlhLThiMWQtZDRhM2YyMzZhMWNhIiwiaWF0IjoxNzM2MjgyNTUyLCJhcHBsaWNhdGlvbl9pZCI6IjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMCJ9.ShYzHEbLurjnMX7DvY3b0P-9Y5KFkotx5jynOlJD019xm6fFloaT3KEw2cHFMmKjBDrBf5Ud9kZSW532jMzAhMSMlN_FylwBV_wtPdCq-XWfOZfFzRywRMUQpGBVaUCoLnxwc6k1GmgmuQ5Kf0acJgNWkMkG_hC096zqkOVgrXckHEzL3X37tmB2FoivbYUaokPRnMl4Il7H26sTM_w2stdCBGMLQBPTy8ushLurKSLfgktOmlI09ps1FiWXzANuonCnF1tKp1pbwRmNSGcUMb9fRtTuWqz7m1Af2VWgHT2OFaefdAJJJefyJbGSPR76KH7UiouxWEEazJztqnpwQA

The above command sets the expiry of the JWT to one day from now, which is the maximum amount of time. You may change the expiration to a shortened amount of time, or regenerate a JWT for the user after the current JWT has expired.

NOTE: In production apps, it is expected that your backend will expose an endpoint that generates JWT per your client request.

Further information