News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Replacing password flow with JWT, not sure how to deal with tokens...
Tags: fax
Mar 12, 2024 at 2:42pm   •   2 replies  •  0 likes
Nick R

Hi!

I am currently modifying one of our applications from password from to JWT. This application uses the Java SDK.

It works but I keep reading about not calling the /auth endpoint too frequently which I assumed transposes into calling authorize() on the rest client with the JWT.

Did I understood that right or are we talking about something else?

As a test I let my application call authorize() more than the documented limit of 5 times and it did not seem to cause any problem so maybe I am misunderstanding something and the limit of 5 times is not for that authorize() call...

Once I call authorize() do I have to do anything to reauthorize the rest client again? The application could stay up for months at a time.

I just want to make sure I call it just the right amount of time, not too frequently but not to the point the app will crash because I have not called it when I should have.

Our application is based on the example that were provided many years ago, using password flow it was calling authorize() for every call...

That being said, there were rarely more than one or two calls per minutes in normal circumstances, this might change...

Thank you and have a nice day!

Nick





2 Answers
answered on Mar 14, 2024 at 2:27pm  

Hi!

This is what I was planning to do....

That said, I must have misread as I thought auth was limited to 5, not 10...

The way our app currently work I would currently call auth twice in a minute if I move the authorize out of the loop.

It has two different threads, one that send faxes which check for work each minute and one that check the status of the sent faxes which runs a lot less frequently (it wakes up every 5 minutes but only start checking the status of sent faxes after 8 minutes or so if I am not mistaken). Both (current) threads would need to call authorize()...

I had read something which suggested using you Java SDK meant that one did not have to deal with token expiries and the like, I guess they were mistaken.

Thank you very much and have a nice day!

Nick


 0
answered on Mar 13, 2024 at 12:24pm  

Consider these examples.

Will hit the /authorize API rate limit

RestClient restClient = new RestClient("RC_CLIENT_ID", "RC_CLIENT_SECRET", "RC_SERVER_URL");

public void start_sending_sms(){
   for (var i=0; i<10; i++){
     send_sms("0123456789")
   }
}

public void send_sms(fromNumber){
    restClient.authorize("RC_JWT");
    CreateSMSMessage requestBody = new CreateSMSMessage();
    requestBody.from = new MessageStoreCallerInfoRequest().phoneNumber(fromNumber);
    requestBody.to = new MessageStoreCallerInfoRequest[] {
    new MessageStoreCallerInfoRequest().phoneNumber("RECIPIENT-NUMBER")
};
    requestBody.text = "Hello World";

    var resp = restClient.restapi().account().extension().sms().post(requestBody);
    System.out.println("SMS sent. Message id: " + resp.id.toString());
}

Correct

RestClient restClient = new RestClient("RC_CLIENT_ID", "RC_CLIENT_SECRET", "RC_SERVER_URL");

public void start_sending_sms(){
    restClient.authorize("RC_JWT");
    for (var i=0; i<10; i++){
       send_sms("0123456789")
    }
}

public void send_sms(fromNumber){
    CreateSMSMessage requestBody = new CreateSMSMessage();
    requestBody.from = new MessageStoreCallerInfoRequest().phoneNumber(fromNumber);
    requestBody.to = new MessageStoreCallerInfoRequest[] {
    new MessageStoreCallerInfoRequest().phoneNumber("RECIPIENT-NUMBER")
};
    requestBody.text = "Hello World";

    var resp = restClient.restapi().account().extension().sms().post(requestBody);
    System.out.println("SMS sent. Message id: " + resp.id.toString());
}

 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us