コード例 #1
0
ファイル: ConfirmUser.cs プロジェクト: jdruin/PowerKnife
        protected override void ProcessRecord()
        {
            string endPoint = "/authenticate_user";

            var baseUri = new Uri(Connection.ChefUrl);

            var requestUri = new Uri(baseUri, endPoint);

            Dictionary<string, string> user = new Dictionary<string, string>();

            user.Add("username", _userName);
            user.Add("password", _password);

            string body = JsonConvert.SerializeObject(user, Formatting.Indented);

            var authenticatedRequest = new AuthenticatedRequest(Connection.UserName, requestUri, HttpMethod.Post, body, String.Empty);

            authenticatedRequest.Sign(Connection.PrivateKey);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Connection.ChefUrl);

                var chefRequest = authenticatedRequest.Create();

                var result = client.SendAsync(chefRequest).Result;

                WriteObject(result.StatusCode);
            }
        }
コード例 #2
0
ファイル: Requester.cs プロジェクト: jdruin/PowerKnife
        public static string MakeRequest(string chefServer,string endPoint,string privateKey,string userId,HttpMethod method,string body, string parameter)
        {
            var baseUri = new Uri(chefServer);

            var requestUri = new Uri(baseUri, endPoint);

            var authenticatedRequest = new AuthenticatedRequest(userId, requestUri,method,body, parameter);

            authenticatedRequest.Sign(privateKey);

            var server = new ChefServer(baseUri);
            string resultContent = server.SendRequest(authenticatedRequest);

            return resultContent;
        }