Persist Access Token Life Time

  • 1
  • Question
  • Updated 4 days ago
I want to persist access token life time remain same once i got after login.is there any way to do it ?. other thing is can i get access token from back end without opening RingCentral Popup or login page ? 

we are having C# and JavaScript base application.
Photo of Hardik Joshi

Hardik Joshi

  • 620 Points 500 badge 2x thumb

Posted 10 months ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 5,584 Points 5k badge 2x thumb
"persist access token life time" is impossible for security reasons. What you can do is to refresh your access token periodically to make it always non-expired.  Refresh token can live as long as a week, so you can refresh access token once a week to make it non-expired.
Photo of Hardik Joshi

Hardik Joshi

  • 620 Points 500 badge 2x thumb
Hi Tyler,

how can i persist token using c# sdk, i am really need to maintain token life time. i am doing 'await rc.Authorize()' every time when i want to communicate with API.

Thanks,
Hardik Joshi
Photo of Tyler Long

Tyler Long, Official Rep

  • 5,584 Points 5k badge 2x thumb
https://github.com/ringcentral/ringcentral-csharp-client/blob/master/RingCentral/RestClient.cs#L54 You can either get or set token.

So once you have the token, get it and serialize it to JSON, save it to somewhere.

After some time, when you need the token again, read the JSON, deserialize it to token and set to the rc object.

Please pay attention:

  • access token expires in an hour. You need to call rc.Refresh() if it expires
  • refresh token expires in a week. You'd have to Authorize() again if it expires
  • each user can have as many as 5 live tokens. If you ask for more (call Authorize() 6 times for example), old tokens will expire.
(Edited)
Photo of Tyler Long

Tyler Long, Official Rep

  • 5,584 Points 5k badge 2x thumb
"can i get access token from back end without opening RingCentral Popup or login page"

Please read http://ringcentral-api-docs.readthedocs.io/en/latest/oauth/#authorization-flows . If you use authorization code flow, RingCentral Popup or login page is inevitable. If you use password flow, you don't need RingCentral login page because you can login via code programmatically. However, not every app supports password flow for security reasons.
(Edited)