Not sure how to do Oauth2 authentication to a web API in C#. If anyone has done so already, could please share some sample code, so I don't have to re-invent the wheel.
Not sure how to do Oauth2 authentication to a web API in C#. If anyone has done so already, could please share some sample code, so I don't have to re-invent the wheel.
To use the RingCentral API, an access and refresh token are needed. The simplest way to get an access token needed for production resources is to complete Two-legged Authorization Flow (OAuth 2.0). The required fields are below:
ApplicationKey granted after successful application/developer registration. Required.
ApplicationSecret granted after successful application/developer registration. Required.
UserName main company number of a RingCentral account or direct extension phone number (unformatted, sequence of digits starting with country code). Required.
Extension extension number to log into for the RingCentral account. Required if main company number is provided as a UserName.
Password for the RingCentral account. Required.
public static string Base64Encode(string plainText) { var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); return System.Convert.ToBase64String(plainTextBytes); }
//Be sure to run "Install-Package Newtonsoft.Json -Version 7.0.1" from your nuget command line. //Be sure to run "Install-Package System.Net.Http -Version 4.0.0" from your nuget command line. HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "BASE64 ENCODED APPKEY:APPSECRET");<br> FormUrlEncodedContent form = new FormUrlEncodedContent(new Dictionary { { "username", "username" }, { "password", "password" }, { "grant_type": "password" }, { "extension": "extension" } } ); Task message = client.PostAsync( "https://platform.devtest.ringcentral.com/restapi/oauth/token", form ); String result = message.Result.Content.ReadAsStringAsync().Result; JObject RCAuth = JObject.Parse( result ); string token = ( string )RCAuth["access_token"] string refreshToken = ( string )RCAuth["refresh_token"]; string tokenExpires = ( string )RCAuth["access_token_expires_in"]; string refreshTokenExpires = ( string )RCAuth["refresh_token_expires_in"];
Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.
Download RingCentral Phone for Desktop:
Tip: switch to the "sandbox mode" before logging in the app:
3 People are following this question.