News & Announcements User Community Developer Community

Welcome to the RingCentral Community

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

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
Re-authorize RestClient using token with .Net SDK
Tags: sdk
Jul 2, 2019 at 9:19am   •   3 replies  •  0 likes
Jesse Merriman

I am having trouble finding a way to authorize a user using an access token with the re-written RingCentral.NET sdk.

In every example I have found in the documentation, it requires you to authorize the RestClient with a username and password. I would much rather authorize with the password once, store the access token, and then handle token refreshes and authorization by passing in the access token.

For api calls (i.e. RingOut) there is no option to pass an access token as a parameter.

As an example scenario, if someone in my app authorizes their account with a username and password, I encrypt and store the access token. If they for some reason close my app and re-open it within a short time period, I cannot re-authorize the app using the decrypted token that I have stored. I have to pass in the username and password again to get a new token.

It seems to me that there is really no point in having a token when using this SDK, unless I am missing something.

Anybody know how I can accomplish this without storing the user credentials?

3 Answers
answered on Jul 2, 2019 at 1:29pm  

This worked perfectly. It appears that an underlying problem was that I was not serializing the token using JsonConvert before I encrypted and stored it.

Problem Solved! Thank you @Phong Vu

answered on Jul 2, 2019 at 12:13pm  

Thank you for the quick response. I will try this out now.

answered on Jul 2, 2019 at 11:15am  

After the first time you authorized a user successfully, you will get a TokenInfo object with all valid values (access token, refresh token etc)

You can then save the token info in the app (a global variable) and use it every time you want to call an API

static TokenInfo token = null;

static private async Task reuse_token()
  RestClient restClient = new RestClient("CLIENTID", "CLIENTSECRET", false);
  if (tokens == null)
    Console.WriteLine("get new token");
    await restClient.Authorize("USERNAME", "EXTENSION", "PASSWORD");
    token = restClient.token;
    Console.WriteLine("reuse token");
    restClient.token = token;
  // use the restClient object to call APIs

Or you can deserialize it and save it in your database. The next time you want to use it, just read it and serialize to a TokenInfo object then set to the restClient class

static string tokenString = "";

static private async Task reuse_token()
  RestClient restClient = new RestClient("CLIENTID", "CLIENTSECRET", false);
  if (tokenString == "")
    Console.WriteLine("get new tokens");
    await restClient.Authorize("USERNAME", "EXTENSION", "PASSWORD");
    tokenString = JsonConvert.SerializeObject(restClient.token);
    Console.WriteLine("reuse tokens string");
    var tokenClass = JsonConvert.DeserializeObject<TokenInfo>(tokenString);
    restClient.token = tokenClass;
  // use the restClient object to call APIs


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

Developer Platform
Integrated Apps
App Gallery
Developer support
Games and rewards

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