Authorization Flow Authentication - C# Quick Start

Welcome to the RingCentral Platform. RingCentral is the leading unified communications platform. From one system developers can integrate with, or build products around all the ways people communicate today: SMS, voice, fax, chat and meetings.

In this Quick Start, we are going to help you authorize a user to login with username and password to get an access token and a refresh token. Let's get started.

Create an App

The first thing we need to do is create an app in the RingCentral Developer Portal. This can be done quickly by clicking the "Create User Login App" button below. Enter a name and description if you want to change them, and click the "Create" button. If you do not yet have a RingCentral account, you will be prompted to create one.

Create User Login App

  1. Login or create an account if you have not done so already.
  2. Go to Console/Apps and click 'Create App' button.
  3. Give your app a name and description, then click Next.
  4. On the second page of the create app wizard enter the following:
    • Select 'Private' for Application Type.
    • Select 'Server/Web' for Platform Type.
  5. On the third page of the create app wizard, select the following permissions:
    • ReadAccounts,ReadCallLog
  6. Specify the redirect Uri as http://localhost:5000/oauth2callback.

When you are done, you will be taken to the app's dashboard. Make note of the Client ID and Client Secret. We will be using those momentarily.

Authorization Flow

Initiate the project

We use .NET core which is cross-platform. You can get it here.

mkdir authorization-demo
cd authorization-demo
dotnet new sln
mkdir my-project
cd my-project
dotnet new web
cd ..
dotnet sln add ./my-project/my-project.csproj
cd my-project
dotnet add package RingCentral.Net
dotnet add package Newtonsoft.Json

Edit Startup.cs

Override Startup.cs with content below. Be sure to edit the variables in with your app credentials.

using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using RingCentral;
using Newtonsoft.Json;

namespace my_project
    public class Startup
        private const string RINGCENTRAL_CLIENT_ID = "<RINGCENTRAL_CLIENT_ID>";
        private const string RINGCENTRAL_SERVER_URL = "";
        private const string RINGCENTRAL_REDIRECT_URL = "http://localhost:5000/oauth2callback";
        private const string SESSION_TOKEN_KEY = "rc-token";

        public void ConfigureServices(IServiceCollection services)

        private static string Html(string body)
            return $@"<!doctype html><html><body>{body}</body></html>";

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            if (env.IsDevelopment()) app.UseDeveloperExceptionPage();
            app.Run(async (context) =>
                var tokenString = context.Session.GetString(SESSION_TOKEN_KEY);
                if (tokenString != null)
                    rc.token = JsonConvert.DeserializeObject<TokenInfo>(tokenString);
                else if (context.Request.Path != "/oauth2callback")
                    var oauthUri = rc.AuthorizeUri(RINGCENTRAL_REDIRECT_URL);
                    await context.Response.WriteAsync(
                        Html($"<h2>RingCentral Authorization Code Flow Authentication</h2><a href=\"{oauthUri}\">Login RingCentral Account</a>"));

                switch (context.Request.Path)
                    case "/":
                        await context.Response.WriteAsync(Html(@"<b><a href=""/logout"">Logout</a></b>
                            <h2>Call APIs</h2>
                                <li><a href=""/test?api=extension"" target=""_blank"">Read Extension Info</a></li>
                                <li><a href=""/test?api=extension-call-log"" target=""_blank"">Read Extension Call Log</a></li>
                                <li><a href=""/test?api=account-call-log"" target=""_blank"">Read Account Call Log</a></li>
                    case "/oauth2callback":
                        context.Request.Query.TryGetValue("code", out var codes);
                        var code = codes.First();
                        await rc.Authorize(code, RINGCENTRAL_REDIRECT_URL);
                        context.Session.SetString(SESSION_TOKEN_KEY, JsonConvert.SerializeObject(rc.token));
                    case "/test":
                        context.Request.Query.TryGetValue("api", out var apis);
                        var api = apis.First();
                        var result = "";
                        switch (api)
                            case "extension":
                                result = await rc.Get<string>("/restapi/v1.0/account/~/extension");
                            case "extension-call-log":
                                result = await rc.Get<string>("/restapi/v1.0/account/~/extension/~/call-log");
                            case "account-call-log":
                                result = await rc.Get<string>("/restapi/v1.0/account/~/call-log");

                        await context.Response.WriteAsync(Html($"<pre>{result}</pre>"));
                    case "/logout":
                        await rc.Revoke();
                        context.Response.StatusCode = 404;

Run Your Code

You are almost done. Now run your app.

$ dotnet run

Open a Web browser and load localhost:5000

If you meet "Unable to configure HTTPS endpoint" issue, please read this article.

Graduate Your App

Congratulations on creating your first RingCentral application. The last step is to graduate your application. We recommend going through this process for your first application so you can understand the steps to take in the future, but also to come to appreciate the care taken by RingCentral to ensure that only high-quality apps are allowed into our production environment.