当前位置: 首页>>代码示例>>C#>>正文


C# RestClient.CallApi方法代码示例

本文整理汇总了C#中RestClient.CallApi方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.CallApi方法的具体用法?C# RestClient.CallApi怎么用?C# RestClient.CallApi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RestClient的用法示例。


在下文中一共展示了RestClient.CallApi方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Authenticate

        // Performs an MFA login interactively using Console
        public static RestClient Authenticate(string podEndpoint)
        {
            RestClient client = new RestClient(podEndpoint);

            Console.Write("Username: ");

            // /security/startauthentication api takes username and version:
            Dictionary<string, dynamic> args = new Dictionary<string, dynamic>();
            args["User"] = Console.ReadLine();
            args["Version"] = "1.0";
            Dictionary<string, dynamic> startResult = client.CallApi("/security/startauthentication", args);

            // First thing to check for is whether we should repeat the call against a more specific pod name (tenant specific url):
            if(startResult["success"] && startResult["Result"].ContainsKey("PodFqdn"))
            {
                Console.WriteLine("Auth redirected to {0}", startResult["Result"]["PodFqdn"]);
                client.Endpoint = string.Format("https://{0}", startResult["Result"]["PodFqdn"]);
                startResult = client.CallApi("/security/startauthentication", args);
            }

            // Get the session id to use in handshaking for MFA
            string authSessionId = startResult["Result"]["SessionId"];
            string tenantId = startResult["Result"]["TenantId"];

            // Also get the collection of challenges we need to satisfy
            var challengeCollection = startResult["Result"]["Challenges"];

            // We need to satisfy one of each challenge collection:
            for(int x = 0; x < challengeCollection.Count; x++)
            {
                // Present the option(s) to the user
                for(int mechIdx = 0; mechIdx < challengeCollection[x]["Mechanisms"].Count; mechIdx++)
                {
                    Console.WriteLine("Option {0}: {1}", mechIdx, MechToDescription(challengeCollection[x]["Mechanisms"][mechIdx]));
                }

                int optionSelect = -1;

                if (challengeCollection[x]["Mechanisms"].Count == 1)
                {
                    optionSelect = 0;
                }
                else
                {
                    while (optionSelect < 0 || optionSelect > challengeCollection[x]["Mechanisms"].Count)
                    {
                        Console.Write("Select option and press enter: ");
                        string optEntered = Console.ReadLine();
                        int.TryParse(optEntered, out optionSelect);
                    }
                }

                AdvanceForMech(client, tenantId, authSessionId, challengeCollection[x]["Mechanisms"][optionSelect]);
            }

            return client;
        }
开发者ID:nate-yocom,项目名称:centrify-samples-dotnet-cs,代码行数:58,代码来源:InteractiveLogin.cs

示例2: AdvanceForMech

        private static void AdvanceForMech(RestClient client, string tenantId, string sessionId, dynamic mech)
        {
            Dictionary<string, dynamic> advanceArgs = new Dictionary<string, dynamic>();
            advanceArgs["TenantId"] = tenantId;
            advanceArgs["SessionId"] = sessionId;
            advanceArgs["MechanismId"] = mech["MechanismId"];
            advanceArgs["PersistentLogin"] = false;

            // Write prompt
            Console.Write(MechToPrompt(mech));

            // Read or poll for response.  For StartTextOob we simplify and require user to enter the response, rather
            //  than simultaenously prompting and polling, though this can be done as well.
            string answerType = mech["AnswerType"];
            switch (answerType)
            {
                case "Text":
                case "StartTextOob":
                    {
                        if (answerType == "StartTextOob")
                        {
                            // First we start oob, to get the mech activated
                            advanceArgs["Action"] = "StartOOB";
                            client.CallApi("/security/advanceauthentication", advanceArgs);
                        }

                        // Now prompt for the value to submit and do so
                        string promptResponse = ReadMaskedPassword();
                        advanceArgs["Answer"] = promptResponse;
                        advanceArgs["Action"] = "Answer";
                        var result = client.CallApi("/security/advanceauthentication", advanceArgs);
                        if (!result["success"] ||
                            !(result["Result"]["Summary"] == "StartNextChallenge" ||
                              result["Result"]["Summary"] == "LoginSuccess"))
                        {
                            throw new ApplicationException(result["Message"]);
                        }
                    }
                    break;
                case "StartOob":
                    // Pure out of band mech, simply poll until complete or fail
                    advanceArgs["Action"] = "StartOOB";
                    client.CallApi("/security/advanceauthentication", advanceArgs);

                    // Poll
                    advanceArgs["Action"] = "Poll";
                    Dictionary<string, dynamic> pollResult = new Dictionary<string, dynamic>();
                    do
                    {
                        Console.Write(".");
                        pollResult = client.CallApi("/security/advanceauthentication", advanceArgs);
                        System.Threading.Thread.Sleep(1000);
                    } while (pollResult["success"] && pollResult["Result"]["Summary"] == "OobPending");

                    // We are done polling, did it work?
                    if (!pollResult["success"] ||
                        !(pollResult["Result"]["Summary"] == "StartNextChallenge" ||
                          pollResult["Result"]["Summary"] == "LoginSuccess"))
                    {
                        throw new ApplicationException(pollResult["Message"]);
                    }
                    break;
            }
        }
开发者ID:nate-yocom,项目名称:centrify-samples-dotnet-cs,代码行数:64,代码来源:InteractiveLogin.cs


注:本文中的RestClient.CallApi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。