Getting started using JWT credentials

Last updated: 2024-02-28Contributors
Edit this page

Before you get started, make sure you are using the best authentication method for your application. JWT is ideally suited for developers just getting started, and for server-to-server authentication. If you need to authenticate individual users, we strongly recommend the more common OAuth flow.

Create a JWT

The key first step in getting started is to generate the JWT token you will be using to authenticate.

Create an app and obtain credentials

The first thing we need to do is create an app in the RingCentral Developer Console. This can be done quickly by clicking the "Create User Login App" button below. Enter a name and description if you want to change them, and click the "Create" button. If you do not yet have a RingCentral account, you will be prompted to create one.

Create JWT App

  1. Login or create an account if you have not done so already.
  2. Go to Console/Apps and click 'Create App' button.
  3. Select "REST API App" under "What type of app are you creating?" Click "Next."
  4. Under "Authentication" select "JWT auth flow."
  5. Under "Security" add the following permissions:
    • ReadAccounts
  6. Under "Security" select "This app is private and will only be callable using credentials from the same RingCentral account."

When you are done, you will be taken to the app's dashboard. Make note of the Client ID and Client Secret. We will be using those momentarily.

Download and edit a .env file

Follow the instructions found in our guide to running Developer Guide code samples. Or:

  1. Download our env-template and save it as a file named .env.
  2. Edit your newly downloaded .env file, setting its variables with the proper values for the app you created above.

JWT auth flow

The JWT auth flow is made a lot simpler when a RingCentral SDK is used.

Install RingCentral JavaScript SDK and some dependencies

$ npm install @ringcentral/sdk --save
$ npm install dotenv --save

Create and edit index.js

Create a file called index.js using the contents below.

require('dotenv').config();

const RC = require('@ringcentral/sdk').SDK
var rcsdk = new RC({
    'server':       process.env.RC_SERVER_URL,
    'clientId':     process.env.RC_APP_CLIENT_ID,
    'clientSecret': process.env.RC_APP_CLIENT_SECRET
});
var platform = rcsdk.platform();

platform.login({
    'jwt':  process.env.RC_USER_JWT
})

platform.on(platform.events.loginSuccess, function(e){
    console.log("User logged in successfully")
});

Install RingCentral Python SDK

$ pip install ringcentral
$ pip install python-dotenv

Create an index.py

Create a file called index.py using the contents below.

#!/usr/bin/env python
from ringcentral import SDK
import os,sys

rcsdk = SDK( os.environ.get('RC_APP_CLIENT_ID'),
             os.environ.get('RC_APP_CLIENT_SECRET'),
             os.environ.get('RC_SERVER_URL') )
platform = rcsdk.platform()

try:
  platform.login( jwt=os.environ.get('RC_USER_JWT') )
except Exception as e:
  sys.exit("Unable to authenticate to platform. Check credentials." + str(e))

print(f'Login with JWT successful.')

Install RingCentral PHP SDK

$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar require ringcentral/ringcentral-php vlucas/phpdotenv

Create an index.php

Create a file called index.php. In this file we'll implement the login page.

<?php
require('vendor/autoload.php');
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
$dotenv->load();

$rcsdk = new RingCentral\SDK\SDK( $_ENV['RC_APP_CLIENT_ID'],
                                  $_ENV['RC_APP_CLIENT_SECRET'],
                                  $_ENV['RC_SERVER_URL'] );
$platform = $rcsdk->platform();
$platform->login( [ "jwt" => $_ENV['RC_USER_JWT'] ] );
?>

Create a new Rails app and install the RingCentral Ruby SDK

$ rails new jwt-flow
$ cd jwt-flow
$ bundle add ringcentral-sdk
$ bundle add dotenv

Create an index.rb

require 'ringcentral'
require 'dotenv/load'

$rc = RingCentral.new(ENV['RC_APP_CLIENT_ID'],
                      ENV['RC_APP_CLIENT_SECRET'],
                      ENV['RC_SERVER_URL'])

$rc.authorize(jwt: ENV['RC_USER_JWT'])

puts "Login with JWT successful."

Create a Visual Studio project

  • Choose Console Application .Net Core -> App
  • Select Target Framework .NET Core 2.1
  • Enter project name "JWT_Auth"
  • Add NuGet package RingCentral.Net (4.1.0) SDK

Edit the file Program.cs

Be sure to edit the variables in ALL CAPS with your app and user credentials. Be sure to also set the recipient's phone number.

using System;
using System.Threading.Tasks;
using RingCentral;

namespace JWT_Auth
{
    class Program
    {
        static RestClient restClient;
        static void Main(string[] args)
        {
            restClient = new RestClient(
                Environment.GetEnvironmentVariable("RC_APP_CLIENT_ID"),
                Environment.GetEnvironmentVariable("RC_APP_CLIENT_SECRET"),
                Environment.GetEnvironmentVariable("RC_SERVER_URL"));
            restClient.Authorize(
                Environment.GetEnvironmentVariable("RC_USER_JWT")).Wait();
            Console.WriteLine("Successfully authed.");
        }
    }
}

Run Your App

You are almost done. Now run your app from Visual Studio.

Create a Java project (using Eclipse IDE)

  • Create a new Java project
  • Select the Gradle Project wizard
  • Enter project name "JWT_QuickStart"
  • Open the build.gradle file and add the RingCentral Java SDK to the project as shown below:
dependencies {
    // ...
    compile 'com.ringcentral:ringcentral:1.4.0'
}
  • Right-click the project in the Package Explorer and choose "Refresh Gradle Project" under the "Gradle" sub-menu

Create a new Java Class

Select "File -> New -> Class" to create a new Java class named "JWTQuickStart"

package JWTQuickStart;

public class JWTQuickStart {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }
}

Edit the file "JWTQuickStart.java".

import com.ringcentral.*;
import com.ringcentral.definitions.*;
import java.io.IOException;

public class JWTQuickStart {
    static RestClient rc;

    public static void main(String[] args) {
        var obj = new JWTQuickStart();
        rc = new RestClient( System.getenv("RC_APP_CLIENT_ID"),
                             System.getenv("RC_APP_CLIENT_SECRET"),
                             System.getenv("RC_SERVER_URL") );
        try {
        rc.authorize(System.getenv("RC_USER_JWT"));
            obj.call_ringout();
        } catch (RestException | IOException e) {
            e.printStackTrace();
        }
        System.out.println("Successfully authed.");
    }
}

Run Your App

You are almost done. Now run your app from Eclipse.