Esempio n. 1
0
 protected virtual void DoExternalIp()
 {
     try
     {
         string content = null;
         // TODO: Check if whatismyip support IPv6
         if ((content = WebOperations.GetPage("http://whatismyip.org")) != string.Empty)
         {
             // TODO: We shouldn't limit ourself to IPv4.
             if (Regex.IsMatch(content, @"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"))
             {
                 try
                 {
                     ExternalIP = IPAddress.Parse(content);
                     Success   |= Functions.ExternalIp;
                 }
                 catch { }
             }
         }
     }
     finally
     {
         Progress = Functions.ExternalRecieveAccess;
     }
 }
Esempio n. 2
0
        public void Should_Nonce_Be_Present_In_Self_Issued()
        {
            rpid = "rp-nonce-unless_code_flow";
            WebRequest.RegisterPrefix("openid", new OIDCWebRequestCreate());

            // given
            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.RedirectUris[0];
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid, MessageScope.Profile, MessageScope.Email, MessageScope.Address, MessageScope.Phone
            };
            requestMessage.State        = WebOperations.RandomString();
            requestMessage.Nonce        = WebOperations.RandomString();
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.IdToken
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[0];
            requestMessage.Validate();

            X509Certificate2   certificate = new X509Certificate2("server.pfx", "", X509KeyStorageFlags.Exportable);
            OpenIdRelyingParty rp          = new OpenIdRelyingParty();

            // when
            OIDCAuthImplicitResponseMessage response = rp.Authenticate("openid://", requestMessage, certificate);
            OIDCIdToken idToken = response.GetIdToken();

            // then
            response.Validate();
        }
Esempio n. 3
0
        public static void TestAvailability(object @value)
        {
            ISiteEndpoint endpoint = value as ISiteEndpoint;

            Stopwatch watcher = new Stopwatch();

            SiteEndpoint endpointBlock = new SiteEndpoint();

            watcher.Start();
            bool isAvailable = WebOperations
                               .CheckUriAvailability(endpoint.EndpointUrl, endpoint.Port, ref endpointBlock);

            watcher.Stop();

            if (endpointBlock != null)
            {
                endpoint.DestinationServer         = endpointBlock.DestinationServer;
                endpoint.DestinationAddress        = endpointBlock.DestinationAddress;
                endpoint.DestinationAddressType    = endpointBlock.DestinationAddressType;
                endpoint.HostInformation           = endpointBlock.HostInformation;
                endpoint.HttpProtocol              = endpointBlock.HttpProtocol;
                endpoint.IsAvailable               = isAvailable;
                endpoint.ServerResponse            = endpointBlock.ServerResponse;
                endpoint.ServerResponseDescription = endpointBlock.ServerResponseDescription;
                endpoint.ResponseTime              = endpointBlock.ResponseTime;
            }

            watcher.Reset();

            if (MultiThreading.ActiveTaskCounter > 0)
            {
                MultiThreading.ActiveTaskCounter--;
            }
        }
        public void Should_Request_And_Use_Claims_Id_Token()
        {
            rpid    = "rp-response_type-id_token+token";
            signalg = "RS256";
            GetProviderMetadata();

            // given
            string    Nonce         = WebOperations.RandomString();
            OIDClaims requestClaims = new OIDClaims();

            requestClaims.IdToken = new Dictionary <string, OIDClaimData>();
            requestClaims.IdToken.Add("name", new OIDClaimData());

            // when
            OIDCAuthImplicitResponseMessage response = (OIDCAuthImplicitResponseMessage)GetAuthResponse(ResponseType.IdToken, Nonce, true, requestClaims);

            // then
            response.Validate();
            Assert.NotNull(response.AccessToken);

            OpenIdRelyingParty rp      = new OpenIdRelyingParty();
            OIDCIdToken        idToken = response.GetIdToken(providerMetadata.Keys, clientInformation.ClientSecret);

            rp.ValidateIdToken(idToken, clientInformation, providerMetadata.Issuer, Nonce);
            Assert.IsNotNullOrEmpty(idToken.Name);
        }
        public void Should_Accept_Encrypted_UserInfo()
        {
            rpid = "rp-user_info-enc";

            // given
            OpenIdRelyingParty rp = new OpenIdRelyingParty();

            string registrationEndopoint         = GetBaseUrl("/registration");
            OIDCClientInformation clientMetadata = new OIDCClientInformation();

            clientMetadata.ApplicationType = "web";
            clientMetadata.ResponseTypes   = new List <ResponseType>()
            {
                ResponseType.IdToken
            };
            clientMetadata.RedirectUris = new List <string>()
            {
                myBaseUrl + "id_token_flow_callback"
            };
            clientMetadata.UserinfoEncryptedResponseAlg = "RSA1_5";
            clientMetadata.UserinfoEncryptedResponseEnc = "A128CBC-HS256";
            clientMetadata.JwksUri = myBaseUrl + "my_public_keys.jwks";
            OIDCClientInformation clientInformation = rp.RegisterClient(registrationEndopoint, clientMetadata);

            OIDClaims requestClaims = new OIDClaims();

            requestClaims.IdToken = new Dictionary <string, OIDClaimData>();
            requestClaims.IdToken.Add("name", new OIDClaimData());

            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.ClientId;
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid, MessageScope.Profile, MessageScope.Address, MessageScope.Phone, MessageScope.Email
            };
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.IdToken, ResponseType.Token
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[0];
            requestMessage.Nonce       = WebOperations.RandomString();
            requestMessage.State       = WebOperations.RandomString();
            requestMessage.Claims      = requestClaims;
            requestMessage.Validate();

            rp.Authenticate(GetBaseUrl("/authorization"), requestMessage);
            semaphore.WaitOne();
            OIDCAuthImplicitResponseMessage authResponse = rp.ParseAuthImplicitResponse(result, requestMessage.Scope, requestMessage.State);

            X509Certificate2 encCert = new X509Certificate2("server.pfx", "", X509KeyStorageFlags.Exportable);
            List <OIDCKey>   myKeys  = KeyManager.GetKeysJwkList(null, encCert);

            // when
            OIDCUserInfoResponseMessage response = GetUserInfo(authResponse.Scope, authResponse.State, authResponse.AccessToken, null, true, null, myKeys);

            // then
            response.Validate();
            Assert.IsNotNullOrEmpty(response.Name);
        }
Esempio n. 6
0
        public static void SuccesfullGetRecived()
        {
            WebOperations   webOps = new WebOperations();
            HttpWebResponse wr     = webOps.SendGetRequestAndReturnResponse();

            Assert.AreEqual(200, (int)wr.StatusCode);
        }
Esempio n. 7
0
        public void Should_Authenticate_With_IdToken_Response_Type()
        {
            rpid = "rp-response_type-id_token";

            // given
            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.ClientId;
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid
            };
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.IdToken
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[1];
            requestMessage.Nonce       = WebOperations.RandomString();
            requestMessage.State       = WebOperations.RandomString();
            requestMessage.Validate();

            OpenIdRelyingParty rp = new OpenIdRelyingParty();

            // when
            rp.Authenticate(GetBaseUrl("/authorization"), requestMessage);
            semaphore.WaitOne();
            OIDCAuthImplicitResponseMessage response = rp.ParseAuthImplicitResponse(result, requestMessage.Scope, requestMessage.State);

            // then
            response.Validate();
        }
Esempio n. 8
0
        private void txtURL_Validating(object sender, CancelEventArgs e)
        {
            if (String.IsNullOrEmpty(txtURL.Text))
            {
                errorProvider1.SetError(txtURL, "Please enter a valid URL");
                return;
            }

            if (!txtURL.Text.StartsWith("http://") && !txtURL.Text.StartsWith("https://"))
            {
                txtURL.Text = "http://" + txtURL.Text; //add http:// to the beginning
            }

            //check that the URL is Valid -- this is quite slow. Perhaps a REGEX would be better.
            if (!WebOperations.IsUrlFormatValid(txtURL.Text))
            {
                errorProvider1.SetError(txtURL, "Please enter a valid URL");
            }
            else
            {
                errorProvider1.SetError(txtURL, "");
            }

            CheckFields();
        }
Esempio n. 9
0
        public static void PrepareCustomWebRequest()
        {
            WebOperations  webOps        = new WebOperations();
            HttpWebRequest request       = webOps.CreateWebRequest();
            HttpWebRequest customRequest = webOps.CreateWebRequest("http://onet.pl");

            Assert.IsFalse(request.Address == customRequest.Address);
        }
Esempio n. 10
0
        public static void SaveWebPageToFile()
        {
            WebOperations webOps = new WebOperations();

            webOps.SaveWebPageToFile();


            FileAssert.Exists(webOps.savedFilePath);
        }
        public void Should_Accept_Signed_UserInfo()
        {
            rpid = "rp-user_info-sign";

            // given
            OpenIdRelyingParty rp = new OpenIdRelyingParty();

            string registrationEndopoint         = GetBaseUrl("/registration");
            OIDCClientInformation clientMetadata = new OIDCClientInformation();

            clientMetadata.ApplicationType = "web";
            clientMetadata.ResponseTypes   = new List <ResponseType>()
            {
                ResponseType.IdToken
            };
            clientMetadata.RedirectUris = new List <string>()
            {
                myBaseUrl + "id_token_flow_callback"
            };
            clientMetadata.UserinfoSignedResponseAlg = "HS256";
            clientMetadata.JwksUri = myBaseUrl + "my_public_keys.jwks";
            OIDCClientInformation clientInformation = rp.RegisterClient(registrationEndopoint, clientMetadata);

            OIDClaims requestClaims = new OIDClaims();

            requestClaims.IdToken = new Dictionary <string, OIDClaimData>();
            requestClaims.IdToken.Add("name", new OIDClaimData());

            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.ClientId;
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid, MessageScope.Profile, MessageScope.Address, MessageScope.Phone, MessageScope.Email
            };
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.IdToken, ResponseType.Token
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[0];
            requestMessage.Nonce       = WebOperations.RandomString();
            requestMessage.State       = WebOperations.RandomString();
            requestMessage.Claims      = requestClaims;
            requestMessage.Validate();

            rp.Authenticate(GetBaseUrl("/authorization"), requestMessage);
            semaphore.WaitOne();
            OIDCAuthImplicitResponseMessage authResponse = rp.ParseAuthImplicitResponse(result, requestMessage.Scope, requestMessage.State);

            // when
            OIDCUserInfoResponseMessage response = GetUserInfo(authResponse.Scope, authResponse.State, authResponse.AccessToken, null, true, clientInformation.ClientSecret, null);

            // then
            response.Validate();
            Assert.IsNotNullOrEmpty(response.Name);
        }
Esempio n. 12
0
        public void Should_Authenticate_With_Claims_In_Scope_Basic()
        {
            rpid = "rp-scope-userinfo_claims";

            // given
            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.ClientId;

            OIDClaims requestClaims = new OIDClaims();

            requestClaims.Userinfo = new Dictionary <string, OIDClaimData>();
            requestClaims.Userinfo.Add("name", new OIDClaimData());

            requestMessage.Scope = new List <MessageScope>()
            {
                MessageScope.Openid, MessageScope.Profile, MessageScope.Email, MessageScope.Address, MessageScope.Phone
            };
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.IdToken, ResponseType.Token
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[0];
            requestMessage.Nonce       = WebOperations.RandomString();
            requestMessage.State       = WebOperations.RandomString();
            requestMessage.Claims      = requestClaims;
            requestMessage.Validate();

            OpenIdRelyingParty rp = new OpenIdRelyingParty();

            rp.Authenticate(GetBaseUrl("/authorization"), requestMessage);
            semaphore.WaitOne();
            OIDCAuthImplicitResponseMessage authResponse = rp.ParseAuthImplicitResponse(result, requestMessage.Scope, requestMessage.State);

            OIDCUserInfoRequestMessage userInfoRequestMessage = new OIDCUserInfoRequestMessage();

            userInfoRequestMessage.Scope = authResponse.Scope;
            userInfoRequestMessage.State = authResponse.State;

            // when
            OIDCUserInfoResponseMessage response = rp.GetUserInfo(GetBaseUrl("/userinfo"), userInfoRequestMessage, authResponse.AccessToken);

            // then
            response.Validate();
            Assert.IsNotNullOrEmpty(response.Name);
            Assert.IsNotNullOrEmpty(response.GivenName);
            Assert.IsNotNullOrEmpty(response.FamilyName);
            Assert.IsNotNullOrEmpty(response.Email);
            Assert.IsNotNull(response.Address);
            Assert.IsNotNullOrEmpty(response.Address.StreetAddress);
            Assert.IsNotNullOrEmpty(response.Address.PostalCode);
            Assert.IsNotNullOrEmpty(response.Address.Locality);
            Assert.IsNotNullOrEmpty(response.Address.Country);
            Assert.IsNotNullOrEmpty(response.PhoneNumber);
        }
Esempio n. 13
0
        public void MainMethod()
        {
            webOperations = new WebOperations();
            webOperations.DownloadFileAsync(new WebOperationDownloadObject()
            {
                Url = new Uri(@"https://www.dropbox.com/s/ovlpue2r4693iy4/A%20Troll%20Never%20Dies....mp4?dl=1")
            });

            webOperations.WebOperationProgress  += Downloading;
            webOperations.WebOperationCompleted += Completed;
        }
        public OIDClientSerializableMessage GetAuthResponse(ResponseType RespType, string Nonce = null, bool Profile = false, OIDClaims Claims = null)
        {
            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.ClientId;
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[0];
            requestMessage.Nonce       = (Nonce == null) ? WebOperations.RandomString() : Nonce;
            requestMessage.State       = WebOperations.RandomString();
            requestMessage.Claims      = Claims;

            if (Profile)
            {
                requestMessage.Scope.Add(MessageScope.Profile);
                requestMessage.Scope.Add(MessageScope.Address);
                requestMessage.Scope.Add(MessageScope.Phone);
                requestMessage.Scope.Add(MessageScope.Email);
            }

            if (ResponseType.Code == RespType)
            {
                requestMessage.ResponseType = new List <ResponseType>()
                {
                    ResponseType.Code
                };
            }
            else if (ResponseType.IdToken == RespType)
            {
                requestMessage.ResponseType = new List <ResponseType>()
                {
                    ResponseType.IdToken, ResponseType.Token
                };
            }

            requestMessage.Validate();

            OpenIdRelyingParty rp = new OpenIdRelyingParty();

            rp.Authenticate(GetBaseUrl("/authorization"), requestMessage);
            semaphore.WaitOne();
            if (ResponseType.Code == RespType)
            {
                return(rp.ParseAuthCodeResponse(result, requestMessage.Scope, requestMessage.State));
            }
            else if (ResponseType.IdToken == RespType)
            {
                return(rp.ParseAuthImplicitResponse(result, requestMessage.Scope, requestMessage.State));
            }

            throw new Exception("Error in parameter passed");
        }
Esempio n. 15
0
        public void Should_Authenticate_With_IdToken_Token_Response_Type_Post()
        {
            rpid = "rp-response_mode-form_post";

            // given
            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.ClientId;
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid
            };
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.IdToken, ResponseType.Token
            };
            requestMessage.ResponseMode = "form_post";
            requestMessage.RedirectUri  = clientInformation.RedirectUris[1];
            requestMessage.Nonce        = WebOperations.RandomString();
            requestMessage.State        = WebOperations.RandomString();
            requestMessage.Validate();

            string             login_url = GetBaseUrl("/authorization") + "?" + requestMessage.SerializeToQueryString();
            OpenIdRelyingParty rp        = new OpenIdRelyingParty();

            // when
            Dictionary <string, object> html = WebOperations.GetUrlContent(WebRequest.Create(login_url), false);

            // then
            Assert.NotNull(html);
            CollectionAssert.Contains(html.Keys, "body");
            string textHtml = (string)html["body"];

            Assert.NotNull(textHtml);
            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(textHtml);
            HtmlNode formNode = document.DocumentNode.SelectNodes("//form")[0];

            Assert.NotNull(formNode);
            Assert.AreEqual(formNode.Attributes["method"].Value.ToLower(), "post");
            Assert.AreEqual(formNode.Attributes["action"].Value.ToLower(), requestMessage.RedirectUri);

            bool hasIdTokenInput = false;

            foreach (HtmlNode innode in formNode.SelectNodes("//input"))
            {
                if (innode.Attributes["name"].Value.Equals("access_token"))
                {
                    hasIdTokenInput = true;
                }
            }
            Assert.IsTrue(hasIdTokenInput);
        }
Esempio n. 16
0
        public void Should_Reject_Id_Token_With_Invalid_ES256_Signature()
        {
            rpid = "rp-id_token-bad_es256_sig";

            // givens
            OpenIdRelyingParty rp = new OpenIdRelyingParty();

            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.ClientId;
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid
            };
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.Token, ResponseType.IdToken
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[1];
            requestMessage.Nonce       = WebOperations.RandomString();
            requestMessage.State       = WebOperations.RandomString();
            requestMessage.Validate();

            // Manipulate keys to make them invalid
            List <OIDCKey> manipulatedKeys = new List <OIDCKey>();

            foreach (OIDCKey curKey in providerMetadata.Keys)
            {
                OIDCKey newKey = curKey.Clone() as OIDCKey;
                if (curKey.N != null)
                {
                    StringBuilder strBuilder = new StringBuilder(newKey.N);
                    strBuilder[17] = (char)(newKey.N[17] + 1);
                    newKey.N       = strBuilder.ToString();
                }
                manipulatedKeys.Add(newKey);
            }

            rp.Authenticate(GetBaseUrl("/authorization"), requestMessage);
            semaphore.WaitOne();

            // when
            OIDCAuthImplicitResponseMessage response = rp.ParseAuthImplicitResponse(result, requestMessage.Scope, requestMessage.State);

            // then
            Assert.NotNull(response.IdToken);
            OIDCIdToken idToken = response.GetIdToken(manipulatedKeys);

            idToken.Validate();
        }
Esempio n. 17
0
 protected virtual void DoInternetAccess()
 {
     try
     {
         string content = null;
         if ((content = WebOperations.GetPage("http://www.google.com")) != string.Empty && content.IndexOf("google", StringComparison.OrdinalIgnoreCase) != -1)
         {
             Success |= Functions.InternetAccess;
         }
     }
     finally
     {
         Progress = Functions.InternalListenAccess;
     }
 }
Esempio n. 18
0
        private bool ValidateDgvAddServices()
        {
            if (dgvAddServices.Rows.Count == 1 && dgvAddServices.Rows[0].IsNewRow == true)
            {
                MessageBox.Show("Please add one or more services to the list.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return(false);
            }

            foreach (DataGridViewRow serviceRow in dgvAddServices.Rows)
            {
                if (serviceRow.IsNewRow == false)
                {
                    // Service Title
                    object cellValue = serviceRow.Cells[0].Value;
                    if ((cellValue == null) || (cellValue.ToString().Trim() == String.Empty))
                    {
                        MessageBox.Show("Please provide a service title for row " + serviceRow.Index.ToString(),
                                        this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return(false);
                    }

                    // Service URL
                    cellValue = serviceRow.Cells[1].Value;
                    if ((cellValue == null) || (cellValue.ToString().Trim() == String.Empty))
                    {
                        MessageBox.Show("Please provide a service URL for row " + serviceRow.Index.ToString(),
                                        this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return(false);
                    }
                    // Trim the query off of the URL
                    string serviceUrl = cellValue.ToString().Trim();
                    try
                    {
                        serviceUrl = WebOperations.GetCanonicalUri(serviceUrl, true);
                    }
                    catch
                    {
                        MessageBox.Show("Please provide a service URL for row " + serviceRow.Index.ToString(),
                                        this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 19
0
        public static IEnumerable <ISiteEndpoint> TestAvailability(this IEnumerable <ISiteEndpoint> endpoints)
        {
            List <ISiteEndpoint> endpointList = new List <ISiteEndpoint>();
            List <Task>          epTaskList   = new List <Task>();

            foreach (ISiteEndpoint value in endpoints)
            {
                Task task = new Task(new Action(delegate
                {
                    ISiteEndpoint endpoint = value as ISiteEndpoint;

                    Stopwatch watcher = new Stopwatch();

                    SiteEndpoint endpointBlock = new SiteEndpoint();
                    watcher.Start();
                    bool isAvailable = WebOperations
                                       .CheckUriAvailability(endpoint.EndpointUrl, endpoint.Port, ref endpointBlock);
                    watcher.Stop();

                    if (endpointBlock != null)
                    {
                        endpoint.DestinationServer         = endpointBlock.DestinationServer;
                        endpoint.DestinationAddress        = endpointBlock.DestinationAddress;
                        endpoint.DestinationAddressType    = endpointBlock.DestinationAddressType;
                        endpoint.HostInformation           = endpointBlock.HostInformation;
                        endpoint.HttpProtocol              = endpointBlock.HttpProtocol;
                        endpoint.IsAvailable               = isAvailable;
                        endpoint.ServerResponse            = endpointBlock.ServerResponse;
                        endpoint.ServerResponseDescription = endpointBlock.ServerResponseDescription;
                        endpoint.ResponseTime              = endpointBlock.ResponseTime;

                        endpointList.Add(endpoint);
                    }

                    watcher.Reset();

                    if (MultiThreading.ActiveTaskCounter > 0)
                    {
                        MultiThreading.ActiveTaskCounter--;
                    }
                }));
                epTaskList.Add(task);
            }
            MultiThreading.Run(epTaskList);
            return(endpointList.AsEnumerable());
        }
Esempio n. 20
0
        private void ProcessLinkQueue()
        {
            while (true)
            {
                while (this.ProcessingLinkQueue.TryDequeue(out String link))
                {
                    Dispatcher.Invoke(() =>
                    {
                        ProgressBarStatusBarItem.Visibility = Visibility.Visible;
                        CountStatusBarItem.Content          = String.Format(CountStatusBarItem.Tag.ToString(), this.ProcessingLinkQueue.Count);
                        MainStatusBarItem.Content           = $"Parsing {link}...";
                    });

                    IHandler handler = HandlerDispatcher.Current.GetLinkHandler(link);

                    if (handler != null)
                    {
                        try
                        {
                            String content       = WebOperations.GetContentAsStringAsync(link).Result;
                            String extractedLink = handler.GetEmbedLinks(content);

                            Dispatcher.Invoke(() =>
                            {
                                if (!String.IsNullOrEmpty(extractedLink))
                                {
                                    LinkItemListView.Items.Add(new LinkItem(extractedLink, link, handler));
                                }
                            });
                        }
                        catch { }
                    }

                    Dispatcher.Invoke(() =>
                    {
                        if (this.ProcessingLinkQueue.Count == 0)
                        {
                            MainStatusBarItem.Content           = "Done";
                            ProgressBarStatusBarItem.Visibility = Visibility.Collapsed;
                        }
                    });
                }

                Thread.Sleep(100);
            }
        }
Esempio n. 21
0
        private async void SearchNews()
        {
            ProgressRingVisibility = Visibility.Visible;

            var newsArticles = await WebOperations.GetNewsAsync(SearchQuery);

            if (newsArticles != null && newsArticles.Any())
            {
                NewsArticles = newsArticles;
            }
            else
            {
                NewsArticles = new List <NewsArticle>();
                await new MessageDialog("No result found", "Bad News!").ShowAsync();
            }

            ProgressRingVisibility = Visibility.Collapsed;
        }
Esempio n. 22
0
        public void Should_Authenticate_With_Claims_In_Scope_Self_Issued()
        {
            rpid = "rp-scope-userinfo_claims";
            WebRequest.RegisterPrefix("openid", new OIDCWebRequestCreate());

            // given
            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.RedirectUris[0];
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid, MessageScope.Profile, MessageScope.Email, MessageScope.Address, MessageScope.Phone
            };
            requestMessage.State        = WebOperations.RandomString();
            requestMessage.Nonce        = WebOperations.RandomString();
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.IdToken
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[0];
            requestMessage.Validate();

            X509Certificate2   certificate = new X509Certificate2("server.pfx", "", X509KeyStorageFlags.Exportable);
            OpenIdRelyingParty rp          = new OpenIdRelyingParty();

            // when
            OIDCAuthImplicitResponseMessage response = rp.Authenticate("openid://", requestMessage, certificate);
            OIDCIdToken idToken = response.GetIdToken();

            // then
            response.Validate();
            rp.ValidateIdToken(idToken, clientInformation, idToken.Iss, requestMessage.Nonce);
            Assert.IsNotNullOrEmpty(idToken.Name);
            Assert.IsNotNullOrEmpty(idToken.GivenName);
            Assert.IsNotNullOrEmpty(idToken.FamilyName);
            Assert.IsNotNullOrEmpty(idToken.Email);
            Assert.IsNotNull(idToken.Address);
            Assert.IsNotNullOrEmpty(idToken.Address.StreetAddress);
            Assert.IsNotNullOrEmpty(idToken.Address.PostalCode);
            Assert.IsNotNullOrEmpty(idToken.Address.Locality);
            Assert.IsNotNullOrEmpty(idToken.Address.Country);
            Assert.IsNotNullOrEmpty(idToken.PhoneNumber);
        }
        private OIDCAuthorizationRequestMessage generateRequestMessage(OpenIDProviderData providerData, OpenIDUrls urls)
        {
            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = providerData.ClientInformation.ClientId;
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid, MessageScope.Profile
            };
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.Code
            };
            requestMessage.RedirectUri = urls.CodeCallbackCommand.ToString();
            requestMessage.State       = WebOperations.RandomString();
            requestMessage.Nonce       = WebOperations.RandomString();
            requestMessage.Validate();

            return(requestMessage);
        }
Esempio n. 24
0
        public LyricContent Retrieve(LyricItem item)
        {
            if (item.Provider.Name != this.Name)
            {
                throw new NotSupportedException("The lyric item data was not from the current provider.");
            }

            String html = WebOperations.GetContentAsString(item.URI.ToString(), Encoding.UTF8);

            Match match = JLyricProvider.LyricParseRegex.Match(html);

            String title    = item.SongTitle;
            String artist   = item.SongArtist;
            String writer   = match.Groups["Writer"].Value;
            String composer = match.Groups["Composer"].Value;

            String[] lyric = match.Groups["Lyric"].Value.Split(new String[] { "<br>" }, StringSplitOptions.None);

            return(new LyricContent(title, artist, writer, composer, lyric, item));
        }
Esempio n. 25
0
        public static IEnumerable <ISiteConnectionString> TestAvaiilabilty(this IEnumerable <ISiteConnectionString> connectionStrings)
        {
            List <ISiteConnectionString> connectionstringList = new List <ISiteConnectionString>();
            List <Task> csTaskList = new List <Task>();

            foreach (ISiteConnectionString value in connectionStrings)
            {
                Task task = new Task(new Action(delegate
                {
                    try
                    {
                        ISiteConnectionString connectionString = value;
                        Stopwatch watcher = new Stopwatch();

                        watcher.Start();
                        XConsole.WriteLine("CheckSQLDatabaseAccesibility:" + connectionString.RawConnectionString);
                        bool isAvailable = WebOperations.CheckSQLDatabaseAccesibility(connectionString?.RawConnectionString);
                        watcher.Stop();

                        connectionString.IsAvailable  = isAvailable;
                        connectionString.ResponseTime = watcher.ElapsedMilliseconds;
                        connectionstringList.Add(connectionString);

                        watcher.Reset();

                        if (MultiThreading.ActiveTaskCounter > 0)
                        {
                            MultiThreading.ActiveTaskCounter--;
                        }
                    }
                    catch (Exception ex)
                    {
                        XConsole.WriteLine(ex.ToString());
                        logManager.Write(ex.ToString());
                    }
                }));
                csTaskList.Add(task);
            }
            MultiThreading.Run(csTaskList);
            return(connectionstringList.AsEnumerable());
        }
Esempio n. 26
0
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);
            loggingSvc.Write($"Service Started -> {_serviceName}");
            string status = "No";

            if (!_bypassAuth)
            {
                authToken     = WebOperations.AuthenticateAgent(AgentName: _serviceName, ServerName: srvName); // Agent authentication
                status        = authToken.Length > 0 ? "Yes" : "No";
                _mainSvcTimer = new Timer(callback: ActionMain, state: null, dueTime: TimeSpan.Zero, period: TimeSpan.FromMinutes(60));
            }
            else
            {
                _mainSvcTimer = new Timer(callback: ActionMain, state: null, dueTime: 0, period: 1);
                Thread.Sleep(1);
                _mainSvcTimer?.Change(dueTime: Timeout.Infinite, period: 0);
            }

            loggingSvc.Write($"Agent Authentication Required -> {status}");
        }
Esempio n. 27
0
        private OIDCAuthorizationRequestMessage generateRequestMessage()
        {
            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.ClientId;
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid
            };
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.Code
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[0];
            requestMessage.State       = WebOperations.RandomString();
            requestMessage.Nonce       = WebOperations.RandomString();
            requestMessage.RequestUri  = myBaseUrl + "request.jwt";
            requestMessage.Validate();

            return(requestMessage);
        }
Esempio n. 28
0
        public void Should_Authenticate_With_Self_Issued_Provider()
        {
            rpid = "rp-response_type-self_issued";
            WebRequest.RegisterPrefix("openid", new OIDCWebRequestCreate());

            // given
            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.RedirectUris[1];
            requestMessage.Scope    = new List <MessageScope>()
            {
                MessageScope.Openid
            };
            requestMessage.State        = WebOperations.RandomString();
            requestMessage.Nonce        = WebOperations.RandomString();
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.IdToken
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[1];
            requestMessage.Validate();

            X509Certificate2   certificate = new X509Certificate2("server.pfx", "", X509KeyStorageFlags.Exportable);
            OpenIdRelyingParty rp          = new OpenIdRelyingParty();

            // when
            OIDCAuthImplicitResponseMessage response = rp.Authenticate("openid://", requestMessage, certificate);

            // then
            OIDCIdToken idToken = response.GetIdToken();

            //The Client MUST validate that the aud (audience) Claim contains the value of the
            //redirect_uri that the Client sent in the Authentication Request as an audience.
            CollectionAssert.Contains(idToken.Aud, requestMessage.RedirectUri);

            //If a nonce value was sent in the Authentication Request, a nonce Claim MUST be present
            //and its value checked to verify that it is the same value as the one that was sent in
            //the Authentication Request.
            Assert.AreEqual(requestMessage.Nonce, idToken.Nonce);
        }
Esempio n. 29
0
        private async void _searchNewsButton_Click(object sender, System.EventArgs e)
        {
            InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);

            imm.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);
            _searchProgressBar.Visibility = ViewStates.Visible;
            _searchProgressBar.Activated  = true;
            _newsArticles = await WebOperations.GetNewsAsync(_searchNewsEditText.Text);

            if (_newsArticles != null && _newsArticles.Any())
            {
                _newsArticlesListView.Adapter = new NewsArticlesAdapter(this, _newsArticles);
            }
            else
            {
                _newsArticlesListView.Adapter = new NewsArticlesAdapter(this, new List <NewsArticle>());
                Toast.MakeText(this, "No result found", ToastLength.Long).Show();
            }

            _searchProgressBar.Visibility = ViewStates.Gone;
            _searchProgressBar.Activated  = false;
        }
Esempio n. 30
0
        public void Should_Nonce_Be_Present_In_Implicit()
        {
            rpid = "rp-nonce-unless_code_flow";

            // given
            OIDCAuthorizationRequestMessage requestMessage = new OIDCAuthorizationRequestMessage();

            requestMessage.ClientId = clientInformation.ClientId;

            OIDClaims requestClaims = new OIDClaims();

            requestClaims.Userinfo = new Dictionary <string, OIDClaimData>();
            requestClaims.Userinfo.Add("name", new OIDClaimData());

            requestMessage.Scope = new List <MessageScope>()
            {
                MessageScope.Openid
            };
            requestMessage.ResponseType = new List <ResponseType>()
            {
                ResponseType.IdToken, ResponseType.Token
            };
            requestMessage.RedirectUri = clientInformation.RedirectUris[0];
            requestMessage.Nonce       = WebOperations.RandomString();
            requestMessage.State       = WebOperations.RandomString();
            requestMessage.Claims      = requestClaims;
            requestMessage.Validate();

            OpenIdRelyingParty rp = new OpenIdRelyingParty();

            rp.Authenticate(GetBaseUrl("/authorization"), requestMessage);
            semaphore.WaitOne();
            OIDCAuthImplicitResponseMessage response = rp.ParseAuthImplicitResponse(result, requestMessage.Scope, requestMessage.State);
            OIDCIdToken idToken = response.GetIdToken(providerMetadata.Keys, clientInformation.ClientSecret);

            // then
            idToken.Validate();
        }