News & Announcements User Community Developer Community

Welcome to the RingCentral Community

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

Search
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
need to help for resolve error in integration with C# SDK
Tags: integrations, sdk
Jan 8, 2018 at 4:07am   •   0 replies  •  0 likes
patel

AuthorizeUri and also authentication did not so please help me


please check below code


class Program

{


static void Main(string[] args)

{


var uri = new Uri(string.Format("http://{0}:{1}";, Config.Instance.AppHost, Config.Instance.AppPort));

using (var host = new NancyHost(uri))

{


host.Start();

Console.WriteLine("Your application is running on " + uri);

Console.WriteLine("Press any [Enter] to close the host.");

Console.ReadLine();

}

}

}


public class DefaultModule : Nancy.NancyModule

{


private const string MyState = "United States";

// must be static. Because every time there is new request, a new instance of this class is created.

static SDK rcsdk = new SDK(Config.Instance.AppKey,

Config.Instance.AppSecret,

Config.Instance.ServerUrl,

"C# OAuth2 demo app", "1.0.0");


public DefaultModule()

{


var authorizeUri = rcsdk.Platform.AuthorizeUri(Config.Instance.RedirectUrl, MyState);

var template = File.ReadAllText("index.html");

Get["/"] = _ =>

{


var tokenJson = "";

var authData = rcsdk.Platform.Auth.GetData();

if (authData.ContainsKey("access_token") && authData["access_token"] != null)

{


tokenJson = JsonConvert.SerializeObject(authData, Formatting.Indented);

}

var page = Engine.Razor.RunCompile(template, "templateKey", null,

new { authorize_uri = authorizeUri, redirect_uri = Config.Instance.RedirectUrl, token_json = tokenJson });

return page;

};

Get["/callback"] = _ =>

{


var authCode = Request.Query.code.Value;

rcsdk.Platform.Authenticate(authCode, Config.Instance.RedirectUrl);

return ""; // js will close this window and reload parent window

};

}

}

-------------------------------------------------------


class Config

{


private static Config instance = null;

private Config() { }


public static Config Instance

{


get

{


if (instance == null)

{


using (var sr = new StreamReader("config.json"))

{


var jsonData = sr.ReadToEnd();

instance = JsonConvert.DeserializeObject<Config>(jsonData);

}

}

return instance;

}

}


[JsonProperty("RC_APP_KEY")]

public string AppKey;


[JsonProperty("RC_APP_SECRET")]

public string AppSecret;


[JsonProperty("RC_APP_SERVER_URL")]

public string ServerUrl;


[JsonProperty("RC_APP_REDIRECT_URL")]

public string RedirectUrl;


[JsonProperty("MY_APP_HOST")]

public string AppHost;


[JsonProperty("MY_APP_PORT")]

public string AppPort;


[JsonProperty("UserName")]

public string UserName;


[JsonProperty("Password")]

public string Password;


[JsonProperty("Extension")]

public string Extension;

}

-----------------------------------






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

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

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