Generating Access token and refresh token and efficiently using them

  • 1
  • Article
  • Updated 2 months ago
  • (Edited)
Most of the developers come across the issue of how to handle access token and refresh token renewal process. Here is an efficient way of handling these issues.

Access token lifetime is 3600s = 1 hour
Refresh token lifetime is 7 days(1 week)

There are 2 ways to handle the renewal process:

1. Renew access token and refresh token for every 1 hour. The expires_at  time provides allows you to know when you need to refresh a token and regularly checking it will allow you to refresh it as and when required. Also, you should detect when any RingCentral API you are calling returns an HTTP Status Code 401 (Unauthorized).
        You can refresh a token that is not expired. The previous access token will be immediately purged and a new access token will be returned. There will only ever be one active access token at a time for each instance. The only downside is the time it takes to issue those refresh commands, so we don't recommend refreshing tokens constantly as it will slow down your app.

2.  If you can’t change the app as mentioned above (for instance, if the app is stateless and you cannot store access/refresh tokens), you should pass “refresh_token_ttl=0” parameter along with /oauth/token API so that refresh tokens are expired immediately after creation.

We provide the developers with SDKs for Javascript, PHP and python which will automatically handle reusing of tokens across instances. You can find the SDKs and documentations here:  https://github.com/ringcentral

Photo of VB

VB, Official Rep

  • 1,470 Points 1k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Rob Admin

Rob Admin

  • 100 Points 100 badge 2x thumb
This is not a great developer experience. We deal with a lot of cloud marketing data platforms, and none of them have such a rigorous authentication process.

For instance, Facebook tokens are valid for 60 days for users and indefinitely for businesses. Twitter tokens do not expire. A 1 hour expiration with a 1 week deadline for refresh tokens is just hostile to platform developers and unhelpful.

This is business phone call data we're dealing with here, not Top Secret security data.
Photo of Lee

Lee

  • 520 Points 500 badge 2x thumb
Totally agree. My experience with this API has been one of frustration compared to others.

The fact I have to have my end users authenticate with RingCentral instead of allowing me as a super admin via server side only on some features is also annoying the hell out of my end users.

I'm integrated with other platforms like RightSignature and it's so much easier. Thank god not every service requires this. If I had known of these issues (even after using the dev platform some problems I didn't find until we went live) I would not have moved off our old internal phone system this year.

While the API team is very responsive to questions and even personally contacted me to help resolve a major issue I was having they do seem to be short staffed if they can't push out updates in a timely manner. It's been over a year for an issue that was first reported (at least publicly on this forum) of not being able to set the caller id on RingOut (except a crazy work around of setting the extension caller id and then having to update it back again after the call connects).
(Edited)
Photo of Rick Smith

Rick Smith

  • 170 Points 100 badge 2x thumb
Could not agree more, I have worked with Twilio and had things up in running in 30mins or so...Get with it RC!