Helper class for managing the storage of credentials in the credential locker
        private Task<Credential> CreateCertificateCredentialAsync(CredentialRequestInfo credentialRequestInfo)
        {
            var tcs = new TaskCompletionSource<Credential>();
            var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            X509Certificate2Collection certificates;
            try
            {
                const string clientAuthOid = "1.3.6.1.5.5.7.3.2"; // Client Authentication OID
                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                // Find Client Authentication certificate
                certificates = store.Certificates.Find(X509FindType.FindByApplicationPolicy, clientAuthOid, true);
            }
            catch (Exception)
            {
                certificates = null;
            }
            finally
            {
                store.Close();
            }

            string url = credentialRequestInfo.ServiceUri;
            ServerInfo serverInfo = IdentityManager.Current.FindServerInfo(url);
            if (certificates != null && certificates.Count >= 1)
            {
                // Let the user select/validate the certificate
                string resourceName = GetResourceName(url);
                string server = serverInfo == null ? Regex.Match(url, "http.?//[^/]*").ToString() : serverInfo.ServerUri;
                string message = resourceName == null
                    ? string.Format("certificate required to access to {0}", server)
                    : string.Format("certificate required to access {0} on {1}", resourceName, server);
                certificates = X509Certificate2UI.SelectFromCollection(certificates, null, message, X509SelectionFlag.SingleSelection);
            }

            if (certificates != null && certificates.Count > 0)
            {
                var credential = new CertificateCredential(certificates[0]) { ServiceUri = serverInfo == null ? url : serverInfo.ServerUri };
                if (AllowSaveCredentials)
                    CredentialManager.AddCredential(credential);

                tcs.TrySetResult(credential);
            }
            else
            {
                // Note : Error type is not that important since the error returned to the user is the initial HTTP error (Authorization Error)
                tcs.TrySetException(new System.Security.Authentication.AuthenticationException());
            }
            return tcs.Task;
        }
 /// <summary>
 /// Retrieves all ArcGISRuntime credentials stored in the Credential Locker.
 /// </summary>
 /// <returns></returns>
 internal IEnumerable <Credential> RetrieveAllSavedCredentials()
 {
     return(CredentialManager.RetrieveAll());
 }
 /// <summary>
 /// Clears all ArcGISRuntime credentials from the Credential Locker.
 /// </summary>
 public void ClearCredentialsCache()
 {
     CredentialManager.RemoveAllCredentials();
 }