Ejemplo n.º 1
0
 private void SsoAuthUriRequestValidatorTest()
 {
     var url = "http:%2F%2Flocalhost:4987%2FLoginCallback.ashx&response_type=code&scope=openid";
     //var url = "c:\\directory\\filename";
     //var url = "https://cardionet.com";
     var req = new SsoAuthUriRequest
     {
         //CallBackUrl = url,
         State = string.Empty
     };
     var valid = ValidateAndShowValidationResult(req, nameof(req));
     //if(valid)
     //{
     //    if (Uri.TryCreate(req.CallBackUrl, UriKind.Absolute, out Uri validatedUri)
     //        //&& result.Scheme == Uri.UriSchemeHttp
     //        )
     //    {
     //        Console.WriteLine($"AbsolutePath:  {validatedUri.AbsolutePath}");
     //        Console.WriteLine($"AbsoluteUri:  {validatedUri.AbsoluteUri}");
     //        Console.WriteLine($"ToString:  {validatedUri.ToString()}");
     //        Console.WriteLine($"PathAndQuery:  {validatedUri.PathAndQuery}");
     //        Console.WriteLine($"Scheme:  {validatedUri.Scheme}");
     //        //Console.WriteLine($":  {validatedUri}");
     //        //Console.WriteLine($":  {validatedUri}");
     //        //Console.WriteLine($":  {validatedUri}");
     //        //Use the valid Uri here
     //        ConsoleDisplay.ShowObject(validatedUri, nameof(validatedUri));
     //    }
     //}
 }
Ejemplo n.º 2
0
        private void UriTest()
        {
            string authHost      = ConfigurationManager.AppSettings["Auth.Host"];
            string authPort      = ConfigurationManager.AppSettings["Auth.Port"];
            string authApiPrefix = ConfigurationManager.AppSettings["Auth.ApiPrefix"];

            if (string.IsNullOrWhiteSpace(authHost) || authHost.Length < 1)
            {
                throw new Exception("The 'Auth.Host' URL define is missing from the config file!");
            }

            // NOTE: the 'Auth.Port' and/or 'Auth.ApiPrefix' defines optiaonly could be missing,
            // in  which case the 'Auth.Host' should hold the full path of the host url
            string rootUri = $"{authHost}{authPort}/{authApiPrefix}".TrimEnd();

            // NOTE: the root url should end with a "/" so that the path would be properlty appended by the HttpClient class to form a full url.
            // if the ending slash is missing, the last word after the last existing slash would be dropped, then the path gets appended rendering a wrong url.
            if (rootUri[rootUri.Length - 1] != '/')
            {
                rootUri += "/";
            }
            var uri = new Uri(rootUri);

            ConsoleDisplay.ShowObject(rootUri, nameof(rootUri));


            return;

            var client = new HttpClient {
                BaseAddress = uri
            };

            ConsoleDisplay.ShowObject(client, nameof(client));

            var payload = new SsoAuthUriRequest {
                CallBackUrl = "http://www.xyz.com"
            };
            var payloadJson              = JsonConvert.SerializeObject(payload, Formatting.None);
            var payloadStringContent     = new StringContent(payloadJson, Encoding.UTF8, "application/json");
            HttpResponseMessage response = client.PostAsync("getssourl", payloadStringContent).GetAwaiter().GetResult();

            ConsoleDisplay.ShowObject(response.IsSuccessStatusCode, nameof(response.IsSuccessStatusCode));
            ConsoleDisplay.ShowObject(response, nameof(response));

            var responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            var result         = JsonConvert.DeserializeObject <SsoAuthUrlResult>(responseString);

            ConsoleDisplay.ShowObject(result, nameof(result));
        }