Getting started using JWT credentials
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
The first thing we need to do is create an app in the RingCentral Developer Portal. 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 Show detailed instructions
- Login or create an account if you have not done so already.
- Go to Console/Apps and click 'Create App' button.
- Select "REST API App" under "What type of app are you creating?" Click "Next."
- Under "Authentication" select "JWT auth flow."
- Under "Security" add the following permissions:
- ReadAccounts
- 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:
- Download our env-template and save it as a file named
.env
. - 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_CLIENT_ID,
'clientSecret': process.env.RC_CLIENT_SECRET
});
var platform = rcsdk.platform();
platform.login({
'jwt': process.env.RC_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_CLIENT_ID'),
os.environ.get('RC_CLIENT_SECRET'),
os.environ.get('RC_SERVER_URL') )
platform = rcsdk.platform()
try:
platform.login( jwt=os.environ.get('RC_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_CLIENT_ID'],
$_ENV['RC_CLIENT_SECRET'],
$_ENV['RC_SERVER_URL'] );
$platform = $rcsdk->platform();
$platform->login( [ "jwt" => $_ENV['RC_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'
RECIPIENT = ENV['RINGOUT_RECIPIENT']
$rc = RingCentral.new(ENV['RC_CLIENT_ID'],
ENV['RC_CLIENRT_SECRET'],
ENV['RC_SERVER_URL'])
$rc.authorize(jwt: ENV['RC_JWT'])
puts "Login with JWT successful."