Skip to content

This repository is used to provide project solution for OAuth demo of ringCentral.

Notifications You must be signed in to change notification settings

Stephen-He-Sydney/SDKDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

SDK Demo

OAuth 2.0 Authorization Code Grant Type For RingCentral C# SDK

Table of contents

  1. Overview

  2. Client application integration

  3. Request authorization code

  4. User login and consent

  5. Retrieve authorization code

  6. Exchange code for token

  7. Get access token

Overview

This document is used to assist developers with the way how to integrate authorization code grant type of C# SDK with your client applications.

Client Application Integration

1. Step One
Request Authorization Code
a) Create request URL
Platform = new SDKModel().GenerateSDK().GetPlatform();
            AuthCodeParams = new Dictionary<string, string>
              {
                  {"response_type", "code" },
                  {"client_id", "8GtalMrJRA2JnozdtdWTlg" }, 
                  {"redirect_uri", "https://localhost:3000/redirect" }, 
                  {"prompt", "login consent" }, 
                  {"state", "statebyStephenHe" },
              };
            SessionHelper.Set("state", AuthCodeParams["state"]);
            SessionHelper.Set("redirect_uri", AuthCodeParams["redirect_uri"]);
b) Redirect Url calling authUrl method
 public ActionResult Index()
 {
        return Redirect(Platform.AuthUrl(AuthCodeParams));
 }
2. Step Two
User Login and Consent

alt text

Enter the provided phone number and password, and click login button

  • Username (phone number): 16505496100
  • Password: rcEngineering@1!
3. Step Three
Retrieve Authorization Code

If the authorize button above is hit, the code and state will be delivered after redirecting page.

string code = Request.QueryString["code"];
string state = Request.QueryString["state"];
4. Step Four
Exchange Code for Token

With the 2 parameters and redirectUri provided before, you are able to retrieve access tokens and others by using following code.

var response = Platform.AuthorizeByAuthCode("authorization_code", code, initialRedirectUri);
5. Step Five
Get Access Token

The response contains following parameters that is required to map with corresponding dictionary keys.

JToken token = JObject.Parse(response.GetBody());
    tokenResponseModel = new TokenResponseModel()
    {
        AccessToken = (string)token.SelectToken("access_token"),
        ExpireIn = (string)token.SelectToken("expires_in"),
        RefreshToken = (string)token.SelectToken("refresh_token"),
        RefreshToken_ExpireIn = (string)token.SelectToken("refresh_token_expires_in"),
        Scope = (string)token.SelectToken("scope"),
        TokenType = (string)token.SelectToken("token_type"),
        OwnerId = (string)token.SelectToken("owner_id"),
        EndpointId = (string)token.SelectToken("endpoint_id")
};

About

This repository is used to provide project solution for OAuth demo of ringCentral.

Resources

Stars

Watchers

Forks

Packages

No packages published