question

Fausto Chepil avatar image
Fausto Chepil asked Fausto Chepil commented

JWT Token Failure

creating a private app that has no user interface, only server to Ring Central interface.

I tried this code snippet with the JWT Token created in my Sandbox with clientid and client-secret. I get the following error:

Unable to authenticate to platform. Check credentials.Either code, or username with password, or jwt has to be provided

CODE testest in 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:
    print(e)
    sys.exit("Unable to authenticate to platform. Check credentials." + str(e))

print(f'Login with JWT successful.')



My app works fine with a user login and password, which is not practical for distribution or as secure as a JWT.

authentication
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Suyash Joshi avatar image
Suyash Joshi answered Fausto Chepil commented

Hi @Fausto Chepil here is a sample project on GitHub that you can clone/download and run it. Just make sure to update the .env file with your credentials including JWT and it should work. The code is in Nodejs, if you need help with Python specifically let us know but with this app you can make sure your credentials and settings are all correct.

1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thank you Suyash.

0 Likes 0 ·
Phong Vu avatar image
Phong Vu answered Fausto Chepil commented

My guess is that you forgot to update the RingCentral Python SDK. Please double check to reinstall.

https://github.com/ringcentral/ringcentral-python

This code works perfectly for me

from ringcentral import SD

RINGCENTRAL_CLIENTID = ''
RINGCENTRAL_CLIENTSECRET = ''
RINGCENTRAL_SERVER = 'https://platform.devtest.ringcentral.com'

rcsdk = SDK( RINGCENTRAL_CLIENTID, RINGCENTRAL_CLIENTSECRET, RINGCENTRAL_SERVER)
platform = rcsdk.platform()

JWT_TOKEN = "jwt-token"

try:
    platform.login( jwt=JWT_TOKEN )
    params = {
        'dateFrom': "2012-01-01T00:00:00.000Z"
        }
    resp = platform.get('/restapi/v1.0/account/~/extension/~/call-log', params)
    for record in resp.json().records:
        print ("Call type: " + record.type)
except Exception as e:
    print ("Unable to authenticate to platform. Check credentials." + str(e))
2 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thank you again Phong!

I should have you on speed dial :)

0 Likes 0 ·

Ringcentral was up to date, but its dependencies were not:

pubnub

requests

Thanks again!

0 Likes 0 ·

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys