简体   繁体   中英

How to use SSO with RingCentral C# SDK?

When using the RingCentral C# Client SDK, how can I use Single Sign-On (SSO) which we require for our Production environment? The SDK is working fine in the Sandbox environment without SSO.

I'm using authorization as follows per the documentation, but this only works for RingCentral password auth, not SSO.

await rc.Authorize("username", "extension", "password");

This is for both the current and older SDKs:

Single Sign-On is only supported via the Authorization Code OAuth 2.0 grant flow which will present the user with an login window with a SSO button that will redirect the user to the SAML Identity Provider (IdP) website for SSO-based auth.

Demo code for how to accomplish this with the two C# SDKs are available here:

https://github.com/ringcentral/ringcentral-demos-oauth/tree/master/csharp-nancy

Here's an excerpt showing the two endpoints for the homepage and OAuth redirect URI:

    public DefaultModule()
    {
        var authorizeUri = rc.AuthorizeUri(Config.Instance.RedirectUrl, MyState);
        var template = File.ReadAllText("index.html");
        Get["/"] = _ =>
        {
            var tokenJson = "";
            var authData = rc.token;
            if (rc.token != null && rc.token.access_token != null)
            {
                tokenJson = JsonConvert.SerializeObject(rc.token, 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;
            rc.Authorize(authCode, Config.Instance.RedirectUrl);
            return ""; // js will close this window and reload parent window
        };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM