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 (Sandbox) Admin Web Portal to configure your development account:
Login with your sandbox account login (main company number) and password.
Configure your sandbox account phone system. If you need help, please see instructions in our Learning Centers
http://success.ringcentral.com/RCSupportPortalLearningCenter?LCtabId=settings_21
Your sandbox account is ready to be used on https://platform.devtest.ringcentral.com environment.
The Getting Started Tutorial at https://developers.ringcentral.com/library/tutorials/get-started.htmlwill help you start working with it.
Please remember, that if you are trying to use call logs or any data created within accounts, you will need to create this data in the sandbox account (data in your production account is not accessible from your sandbox account).
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.