RetrieveAll() public method

public RetrieveAll ( ) : IVectorView
return IVectorView
        void ChangeUser_Click(object sender, RoutedEventArgs e)
        {
            Page outputFrame = (Page)rootPage.OutputFrame.Content;
            Page inputFrame  = (Page)rootPage.InputFrame.Content;

            try
            {
                Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                IReadOnlyList <PasswordCredential>         creds = vault.RetrieveAll();
                foreach (PasswordCredential c in creds)
                {
                    try
                    {
                        vault.Remove(c);
                    }
                    catch (Exception Error) // Stored credential was deleted
                    {
                        DebugPrint(Error.ToString());
                    }
                }
            }
            catch (Exception Error) // No stored credentials, so none to delete
            {
                DebugPrint(Error.ToString());
            }
            Reset1();
            CleanCombobox();
            CheckBox AuthenticationFailCheck = outputFrame.FindName("AuthenticationFailCheck") as CheckBox;

            AuthenticationFailCheck.IsChecked = false;
            TextBox WelcomeMessage = inputFrame.FindName("WelcomeMessage") as TextBox;

            WelcomeMessage.Text = "User has been changed, please resign in with new credentials, choose save and launch scenario again";
        }
Ejemplo n.º 2
0
        public string GetSecretFor(string name)
        {
            var vault = new PasswordVault();
            try
            {
                if (vault.RetrieveAll().Count == 0)
                {
                    return "";
                }

                var credentialList = vault.FindAllByResource(_key);

                return credentialList
                    .Where(x => x.UserName == name)
                    .Select(x =>
                    {
                        x.RetrievePassword();
                        return x.Password;
                    })
                    .FirstOrDefault();
            }
            catch (Exception)
            {
                // Exception is thrown if the vault isn't properly initialised
                return "";
            }
        }
Ejemplo n.º 3
0
        public void Clear()
        {
            var allCredentials = _passwordVault.RetrieveAll();

            foreach (var credential in allCredentials)
            {
                _passwordVault.Remove(credential);
            }
        }
Ejemplo n.º 4
0
        public static void ClearRoamedAccounts()
        {
            PasswordVault vault = new PasswordVault();

            foreach (var credential in vault.RetrieveAll())
            {
                vault.Remove(credential);
            }
        }
Ejemplo n.º 5
0
        public static string GetPassword()
        {
            PasswordVault passwordVault = new PasswordVault();
            if (!passwordVault.RetrieveAll().Any(credential => credential.UserName == UserNameText && credential.Resource == ResourceText))
            {
                SetPassword();
            }

            return passwordVault.Retrieve(ResourceText, UserNameText).Password;
        }
 static bool InitializePasswordVaultInTheBackground()
 {
     // Explicitly place this task on a background thread.
     Task.Factory.StartNew(() =>
     {
         // any call to the password vault will load the vault.
         var vault = new PasswordVault();
         vault.RetrieveAll();
     });
     return true;
 }
 void Scenario4Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Windows.Security.Credentials.PasswordVault v     = new Windows.Security.Credentials.PasswordVault();
         IReadOnlyList <PasswordCredential>         creds = v.RetrieveAll();
         DeleteSummary.Text = "Number of credentials deleted: " + creds.Count;
         foreach (PasswordCredential c in creds)
         {
             v.Remove(c);
         }
         // GetAll is a snapshot in time, so to reflect the updated vault, get all credentials again
         creds = v.RetrieveAll();
         // The credentials should now be empty
     }
     catch (Exception Error)
     {
         DebugPrint(Error.ToString());
     }
 }
 /// <summary>
 /// Clears PasswordVault of any saved password
 /// </summary>
 public static void ClearAllSavedPasswords()
 {
     try
     {
         var vault = new Windows.Security.Credentials.PasswordVault();
         foreach (var p in vault.RetrieveAll())
         {
             vault.Remove(p);
         }
     }
     catch (Exception) { }
 }
Ejemplo n.º 9
0
        public void SaveIfttt(string key)
        {
            if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key));

            var vault = new PasswordVault();

            foreach (var item in vault.RetrieveAll().Where(v => v.Resource == "ifttt"))
            {
                vault.Remove(item);
            }

            vault.Add(new PasswordCredential("ifttt", "key", key));
        }
Ejemplo n.º 10
0
        public string GetIfttt()
        {
            var vault = new PasswordVault();

            var credentials = vault.RetrieveAll().Where(v => v.Resource == "ifttt");
            if (credentials.Count(c => c.UserName == "key") != 1)
                return null;

            var key = credentials.Single();
            key.RetrievePassword();

            return key.Password;
        }
        public Tuple<string, string> GetLoginInfo()
        {
            var passwordValut = new Windows.Security.Credentials.PasswordVault();
            var list = passwordValut.RetrieveAll();

            var login = list.FirstOrDefault(i => String.Compare(i.Resource, RESOURCE) == 0);
            if (login != null)
            {
                login.RetrievePassword();
                return new Tuple<string, string>(login.UserName, login.Password);
            }
            return new Tuple<string, string>(String.Empty, String.Empty);
        }
Ejemplo n.º 12
0
        private void MainPage_AccountCommandsRequested(AccountsSettingsPane sender,
			AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
            var credDeletedHandler = new CredentialCommandCredentialDeletedHandler(h => AccountsSettingsPane.Show());

            var vault = new PasswordVault();
            var creds = vault.RetrieveAll();

            foreach (PasswordCredential c in creds)
            {
                var credCommand1 = new CredentialCommand(c, credDeletedHandler);
                args.CredentialCommands.Add(credCommand1);
            }
        }
Ejemplo n.º 13
0
 public static void SetNotifierCredential(string username, string password)
 {
     var vault = new PasswordVault();
     var credentials = vault.RetrieveAll();
     foreach (var credential in credentials)
     {
         if (credential.Resource == "NOTCRED" && credential.UserName == username)
         {
             vault.Remove(credential);
         }
     }
     if (password != null)
     {
         vault.Add(new PasswordCredential("NOTCRED", username, password));
     }
 }
Ejemplo n.º 14
0
        public static void DeserializeRoamedAccounts()
        {
            PasswordVault vault = new PasswordVault();

            App.Accounts.Clear();

            foreach (var credential in vault.RetrieveAll())
            {
                credential.RetrievePassword();

                Account a = new Account();
                a.Name = credential.UserName;
                a.SecretKey = credential.Password;

                App.Accounts.Add(a);
            }
        }
Ejemplo n.º 15
0
 public static List<string[]> GetNotifierCredentials()
 {
     List<string[]> returnedCredentials = new List<string[]>();
     var vault = new PasswordVault();
     var credentials = vault.RetrieveAll();
     if (credentials.Count == 0) return returnedCredentials;
     foreach (var credential in credentials)
     {
         if (credential.Resource == "NOTCRED")
         {
             credential.RetrievePassword();
             string[] credentialData = { credential.UserName, credential.Password };
             returnedCredentials.Add(credentialData);
         }
     }
     return returnedCredentials;
 }
Ejemplo n.º 16
0
        private bool SaveSettings(string user, string password, string host, string port, Scheme scheme)
        {
            var vault = new PasswordVault();
            foreach (var pwdCredential in vault.RetrieveAll())
            {
                vault.Remove(pwdCredential);
            }

            vault.Add(new PasswordCredential(ResourceName, user, password));

            var res = vault.FindAllByUserName(user);
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
            localSettings.Values["host"] = host;
            localSettings.Values["scheme"] = scheme.ToString();
            localSettings.Values["port"] = port.ToString();       
            MainPage.SplunkService = null;
            return true;
        }
Ejemplo n.º 17
0
        public void SaveFifthplay(string username, string password)
        {
            if (username == null) throw new ArgumentNullException(nameof(username));
            if (password == null) throw new ArgumentNullException(nameof(password));

            var vault = new PasswordVault();

            foreach (var item in vault.RetrieveAll().Where(v => v.Resource == "fifthplay"))
            {
                vault.Remove(item);
            }

            vault.Add(new PasswordCredential("fifthplay", username, password));

            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("fifthplay-username"))
                ApplicationData.Current.LocalSettings.Values.Add("fifthplay-username", username);
            else
                ApplicationData.Current.LocalSettings.Values["fifthplay-username"] = username;
        }
 public void SaveLogin(string username, string password)
 {
     PasswordCredential pc;
     var passwordVault = new Windows.Security.Credentials.PasswordVault();
     var list = passwordVault.RetrieveAll().Where(i => String.Compare(i.Resource, RESOURCE) == 0);
     if((pc = list.FirstOrDefault(i => String.Compare(i.UserName, username) == 0)) != null)
     {
         passwordVault.Remove(pc);
         passwordVault.Add(new Windows.Security.Credentials.PasswordCredential(RESOURCE, username, password));
     }
     else if(list.Count() > 0)
     {
         foreach(var p in list)
         {
             passwordVault.Remove(p);
         }
     }
     passwordVault.Add(new Windows.Security.Credentials.PasswordCredential(RESOURCE, username, password));
 }
Ejemplo n.º 19
0
        private void Reset_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                TextBox InputResourceValue = rootPage.FindName("InputResourceValue") as TextBox;
                InputResourceValue.Text = "";
                TextBox InputUserNameValue = rootPage.FindName("InputUserNameValue") as TextBox;
                InputUserNameValue.Text = "";
                PasswordBox InputPasswordValue = rootPage.FindName("InputPasswordValue") as PasswordBox;
                InputPasswordValue.Password = "";
                TextBox ErrorMessage = rootPage.FindName("ErrorMessage") as TextBox;
                ErrorMessage.Text = "";

                Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                IReadOnlyList <PasswordCredential>         creds = vault.RetrieveAll();
                foreach (PasswordCredential c in creds)
                {
                    try
                    {
                        vault.Remove(c);
                    }
                    catch (Exception Error) // Stored credential was deleted
                    {
                        DebugPrint(Error.ToString());
                    }
                }

                DebugPrint("Scenario has been reset. All credentials are removed.");
            }
            catch (Exception Error)
            {
                //
                // Bad Parameter, Machine infor Unavailable errors are to be handled here.
                //
                DebugPrint(Error.Message);
            }
        }
Ejemplo n.º 20
0
        public IList<SecureAuthCode> ReadAll()
        {
            var vault = new PasswordVault();
            try
            {
                if (vault.RetrieveAll().Count == 0)
                {
                    return new List<SecureAuthCode>();
                }

                var credentialList = vault.FindAllByResource(_key);

                return credentialList.Select(x =>
                {
                    x.RetrievePassword();
                    return new SecureAuthCode(x.UserName, x.Password);
                }).ToList();
            }
            catch (Exception)
            {
                // Exception is thrown if the vault isn't properly initialised
                return new List<SecureAuthCode>();
            }
        }
Ejemplo n.º 21
0
        private void Reset_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                TextBox InputResourceValue = rootPage.FindName("InputResourceValue") as TextBox;
                InputResourceValue.Text = "";
                TextBox InputUserNameValue = rootPage.FindName("InputUserNameValue") as TextBox;
                InputUserNameValue.Text = "";
                PasswordBox InputPasswordValue = rootPage.FindName("InputPasswordValue") as PasswordBox;
                InputPasswordValue.Password = "";
                TextBox ErrorMessage = rootPage.FindName("ErrorMessage") as TextBox;
                ErrorMessage.Text = "";

                Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                IReadOnlyList<PasswordCredential> creds = vault.RetrieveAll();
                foreach (PasswordCredential c in creds)
                {
                    try
                    {
                        vault.Remove(c);
                    }
                    catch (Exception Error) // Stored credential was deleted
                    {
                        DebugPrint(Error.ToString());
                    }
                }

                DebugPrint("Scenario has been reset. All credentials are removed.");
            }
            catch (Exception Error)
            {
                //
                // Bad Parameter, Machine infor Unavailable errors are to be handled here.
                //
                DebugPrint(Error.Message);
            }
        }                
Ejemplo n.º 22
0
        private void Read_Click(object sender, RoutedEventArgs e)
        {
            TextBox InputResourceValue = rootPage.FindName("InputResourceValue") as TextBox;
            TextBox InputUserNameValue = rootPage.FindName("InputUserNameValue") as TextBox;
            String result = "";

            try
            {
                //
                //Read a credential from PasswordVault by supplying resource or username
                //
                Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                IReadOnlyList<PasswordCredential> creds = null;
                PasswordCredential cred = null;

                //
                //If both resource and username are empty, you can use RetrieveAll() to enumerate all credentials
                //
                if (InputUserNameValue.Text == "" && InputResourceValue.Text == "")
                {
                    DebugPrint("Retrieving all credentials since resource or username are not specified.");
                    creds = vault.RetrieveAll();
                }
                //
                //If there is only resouce, you can use FindAllByResource() to enumerate by resource. 
                //Note: the password will not be returned, you need to call retrieveAll with returned resouce and username to get the credential with password
                //
                else if (InputUserNameValue.Text == "")
                {
                    DebugPrint("Retrieve credentials by resouces that you provided");
                    creds = vault.FindAllByResource(InputResourceValue.Text);      
                }
                //
                //If there is only username, you can use findbyusername() to enumerate by resource. 
                //Note: the password will not be returned, you need to call retrieveAll with returned resouce and username to get the credential with password 
                //
                else if (InputResourceValue.Text == "")
                {
                    DebugPrint("Retrieve credentials by username that you provided"); 
                    creds = vault.FindAllByUserName(InputUserNameValue.Text);
                }
                //
                //Read by explicit resource and username name, result will be a single credential if it exists. Password will be returned.
                //
                else
                    cred = vault.Retrieve(InputResourceValue.Text, InputUserNameValue.Text);

                //
                //Output credential added to debug spew
                //
                if (creds != null)
                {
                    DebugPrint("There are " + creds.Count + " credential(s) found.");
                    foreach (PasswordCredential c in creds)
                    {
                        try
                        {
                            PasswordCredential c1 = vault.Retrieve(c.Resource.ToString(), c.UserName.ToString());
                            result = "Credential read successfully. " + "Resource: " + c.Resource.ToString() + ", " + "Username: "******"Password: "******".";
                            DebugPrint(result.ToString());
                        }
                        catch (Exception Error)
                        {
                            DebugPrint(Error.Message);
                        }
                    }
                }

                else if (cred != null)
                {
                    result = "Credential read successfully. " + "Resource: " + cred.Resource + ", " + "Username: "******"Password: "******".";
                    DebugPrint(result.ToString());
                }
                else
                {
                    result = "Credential not found.";
                    DebugPrint(result.ToString());
                }

                
            }
            catch (Exception Error) // No stored credentials, so none to delete
            {
                if (Error.HResult == -2147023728)
                    DebugPrint("Credential not found.");
                else
                    DebugPrint(Error.Message);
            }
            

        }
Ejemplo n.º 23
0
 private static void storeCredential(string resource, string username, string value)
 {
     var vault = new PasswordVault();
     var credentials = vault.RetrieveAll();
     foreach (var credential in credentials)
     {
         if (credential.UserName == resource + username) vault.Remove(credential);
     }
     if (value != null)
     {
         vault.Add(new PasswordCredential(resource, resource + username, value));
     }
 }
Ejemplo n.º 24
0
        public void Remove(SecureAuthCode value)
        {
            var vault = new PasswordVault();
            try
            {
                if (vault.RetrieveAll().Count == 0)
                {
                    return;
                }

                var cred = vault.Retrieve(_key, value.Name);
                vault.Remove(cred);
            }
            catch (Exception)
            {
                // Exception is thrown if the vault isn't properly initialised
                return;
            }
        }
        void MainPage_AccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
            // Callback invoked to request the app for accounts when the accounts flyout is about to be displayed
            // Get the Deferral object and do some async operation if needed
            var Deferral = args.GetDeferral();

            // do some async operation
            //Uri uri = new Uri("ms-appx:///Assets/Smalllogo.png");
            //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);


            // Add CredLocker Credentials
            CredentialCommandCredentialDeletedHandler credDeletedHandler = new CredentialCommandCredentialDeletedHandler(CredentialDeletedHandler);

            Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
            IReadOnlyList <PasswordCredential>         creds = vault.RetrieveAll();

            if (creds.Count == 0)
            {
                args.HeaderText = "There is not credential saved by the sample app, please go to Scenario 1 and add some credential, then try again.";
            }
            else
            {
                args.HeaderText = "Here are the credentials saved by sample app in Scenario 1.";
            }

            foreach (PasswordCredential c in creds)
            {
                try
                {
                    CredentialCommand credCommand1 = new CredentialCommand(c, credDeletedHandler);
                    // Deleted is invoked after the system deletes the credential
                    args.CredentialCommands.Add(credCommand1);
                }
                catch (Exception Error) // Stored credential was deleted
                {
                    DebugPrint(Error.ToString());
                }
            }

            try
            {
                // Add Global commands
                Object commandID = 1;
                UICommandInvokedHandler appCmdInvokedHandler = new UICommandInvokedHandler(CommandInvokedHandler);

                // SettingsCommand is an existing WinRT class used in the SettingsPane
                SettingsCommand command = new SettingsCommand(
                    commandID,
                    "App Specific Command Label...",
                    appCmdInvokedHandler);
                args.Commands.Add(command);
                // Add more commands here
            }
            catch (Exception Error) // No stored credentials, so none to delete
            {
                DebugPrint(Error.Message);
            }

            // Complete the Deferral()
            Deferral.Complete();
        }
Ejemplo n.º 26
0
 public void Reset()
 {
     var vault = new PasswordVault();
     foreach (var passwordCredential in vault.RetrieveAll())
         vault.Remove(passwordCredential);
 }
 /// <summary>
 /// Removes all ArcGISRuntime credentials.
 /// </summary>
 /// <remark>Remove application credentials only.</remark>
 public static void RemoveAllCredentials()
 {
     var passwordVault = new PasswordVault();
     foreach (PasswordCredential passwordCredential in passwordVault.RetrieveAll())
     {
         if (passwordCredential.Resource.StartsWith(ResourcePrefix))
             passwordVault.Remove(passwordCredential);
     }
 }
        private void Launch_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Page          outputFrame = (Page)rootPage.OutputFrame.Content;
                Page          inputFrame  = (Page)rootPage.InputFrame.Content;
                List <String> itemsource1 = new List <String>();
                List <String> itemsource2 = new List <String>();
                List <Object> l           = new List <Object>();
                List <Object> m           = new List <Object>();
                Reset1();
                CleanCombobox();
                CheckBox AuthenticationFailCheck = outputFrame.FindName("AuthenticationFailCheck") as CheckBox;
                TextBox  WelcomeMessage          = inputFrame.FindName("WelcomeMessage") as TextBox;
                ComboBox SelectResource          = inputFrame.FindName("SelectResource") as ComboBox;
                ComboBox SelectUser = inputFrame.FindName("SelectUser") as ComboBox;
                if (AuthenticationFailCheck.IsChecked == true)
                {
                    WelcomeMessage.Text = "Blocked";
                }
                else
                {
                    try
                    {
                        Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                        IReadOnlyList <PasswordCredential>         creds = vault.RetrieveAll();

                        foreach (var c in (IEnumerable <PasswordCredential>)creds)
                        {
                            itemsource1.Insert(0, c.Resource);
                        }

                        itemsource1.Sort();
                    }
                    catch (Exception Error) // If there are no stored credentials, no list to populate
                    {
                        DebugPrint(Error.ToString());
                    }
                    itemsource1.Insert(0, "Add new resource");
                    itemsource1.Insert(0, "");
                    l.AddRange(itemsource1);
                    SelectResource.ItemsSource   = l;
                    SelectResource.SelectedIndex = 0;

                    try
                    {
                        Windows.Security.Credentials.PasswordVault vault  = new Windows.Security.Credentials.PasswordVault();
                        IReadOnlyList <PasswordCredential>         cred2s = vault.RetrieveAll();

                        foreach (var c in (IEnumerable <PasswordCredential>)cred2s)
                        {
                            itemsource2.Insert(0, c.UserName);
                        }

                        itemsource2.Sort();
                    }
                    catch (Exception Error) // If there are no stored credentials, no list to populate
                    {
                        DebugPrint(Error.ToString());
                    }
                    itemsource2.Insert(0, "Add new resource");
                    itemsource2.Insert(0, "");
                    m.AddRange(itemsource2);
                    SelectUser.ItemsSource   = m;
                    SelectUser.SelectedIndex = 0;

                    WelcomeMessage.Text = "Scenario is ready, please sign in";
                }
            }
            catch (Exception Error)
            {
                //
                // Bad Parameter, Machine infor Unavailable errors are to be handled here.
                //
                DebugPrint(Error.ToString());
            }
        }
Ejemplo n.º 29
0
 private static void LoadPasswordVault()
 {
     // any call to the password vault will load the vault
     Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
     vault.RetrieveAll();
 }
        /// <summary>
        /// Logs the user out.
        /// </summary>
        public async Task LogoutAsync()
        {
            // Use the PasswordVault to securely store and access credentials.
            var vault = new PasswordVault();

            var credential = vault.RetrieveAll().FirstOrDefault();
            if (credential != null)
            {
                // Create a user from the stored credentials.
                var user = new MobileServiceUser(credential.UserName);
                credential.RetrievePassword();
                user.MobileServiceAuthenticationToken = credential.Password;

                // Set the user from the stored credentials.
                AzureAppService.Current.CurrentUser = user;

                try
                {
                    // Try to return an item now to determine if the cached credential has expired.
                    await AzureAppService.Current.LogoutAsync();
                }
                catch (MobileServiceInvalidOperationException)
                {
                    // We are not interested in any exceptions here
                }
                finally
                {
                    // Make sure vault is cleaned up
                    ResetPasswordVault();
                }
            }

            await Task.FromResult(0);
        }
        /// <summary>
        /// Restores the sign in status.
        /// </summary>
        /// <returns>Returns the current user.</returns>
        public async Task<User> RestoreSignInStatus()
        {
            // Use the PasswordVault to securely store and access credentials.
            var vault = new PasswordVault();

            // Try to get an existing credential from the vault.
            var credential = vault.RetrieveAll().FirstOrDefault();

            if (credential != null)
            {
                // Create a user from the stored credentials.
                var user = new MobileServiceUser(credential.UserName);
                credential.RetrievePassword();
                user.MobileServiceAuthenticationToken = credential.Password;

                // Set the user from the stored credentials.
                AzureAppService.Current.CurrentUser = user;

                try
                {
                    var userContract = await AzureAppService.Current.InvokeApiAsync<UserContract>("User", HttpMethod.Get,
                        null);

                    return userContract.ToDataModel();
                }
                catch (MobileServiceInvalidOperationException invalidOperationException)
                {
                    if (invalidOperationException.Response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        // Remove the credentials.
                        ResetPasswordVault();

                        AzureAppService.Current.CurrentUser = null;
                        credential = null;
                    }
                }
            }

            return null;
        }
 private static void LoadPasswordVault()
 {
     // any call to the password vault will load the vault
     PasswordVault vault = new PasswordVault();
     vault.RetrieveAll();
 }
        private void Reset_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                InputResourceValue.Text = "";
                InputUserNameValue.Text = "";
                InputPasswordValue.Password = "";

                PasswordVault vault = new PasswordVault();
                IReadOnlyList<PasswordCredential> creds = vault.RetrieveAll();
                foreach (PasswordCredential c in creds)
                {
                    try
                    {
                        vault.Remove(c);
                    }
                    catch (Exception Error)
                    {
                        rootPage.NotifyUser(Error.Message, NotifyType.ErrorMessage);
                    }
                }

                rootPage.NotifyUser("Scenario has been reset. All credentials are removed.", NotifyType.StatusMessage);
            }
            catch (Exception Error)
            {
                // Bad Parameter, Machine info Unavailable errors are to be handled here.
                rootPage.NotifyUser(Error.Message, NotifyType.ErrorMessage);
            }
        }
Ejemplo n.º 34
0
 private static void LoadPasswordVault()
 {
     // any call to the password vault will load the vault
     Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
     vault.RetrieveAll();
 }
        /// <summary>
        /// Retrieves all ArcGISRuntime credentials stored in the Credential Locker.
        /// </summary>
        public static IEnumerable<Credential>  RetrieveAll()
        {
            var passwordVault = new PasswordVault();
            var credentials = new List<Credential>();
            foreach (PasswordCredential passwordCredential in passwordVault.RetrieveAll().Where(pc => pc.Resource.StartsWith(ResourcePrefix)))
            {
                Credential credential = null;
                passwordCredential.RetrievePassword();
                string userName = passwordCredential.UserName;
                string passwordValue = passwordCredential.Password; // value stored as password
                string serviceUrl = passwordCredential.Resource.Substring(ResourcePrefix.Length);

                // Create the credential depending on the type
                if (passwordValue.StartsWith(PasswordPrefix))
                {
                    string password = passwordValue.Substring(PasswordPrefix.Length);
                    credential = new ArcGISTokenCredential { ServiceUri = serviceUrl, UserName = userName, Password = password, Token = "dummy"}; // dummy to remove once the token will be refreshed pro actively
                }
                else if (passwordValue.StartsWith(OAuthRefreshTokenPrefix))
                {
                    string refreshToken = passwordValue.Substring(OAuthRefreshTokenPrefix.Length);
                    credential = new OAuthTokenCredential
                    {
                        ServiceUri = serviceUrl,
                        UserName = userName,
                        OAuthRefreshToken = refreshToken,
                        Token = "dummy"
                    };
                }
                else if (passwordValue.StartsWith(OAuthAccessTokenPrefix))
                {
                    string token = passwordValue.Substring(OAuthAccessTokenPrefix.Length);
                    credential = new OAuthTokenCredential
                    {
                        ServiceUri = serviceUrl,
                        UserName = userName,
                        Token = token,
                    };
                }
                else if (passwordValue.StartsWith(NetworkCredentialPasswordPrefix))
                {
                    string password = passwordValue.Substring(NetworkCredentialPasswordPrefix.Length);
                    credential = new ArcGISNetworkCredential {ServiceUri = serviceUrl, Credentials = new NetworkCredential(userName, password)};
                }

                if (credential != null)
                {
                    credentials.Add(credential);
                }
            }
            return credentials;
        }
Ejemplo n.º 36
0
 private static string getStoredCredential(string resource, string username)
 {
     var vault = new PasswordVault();
     var credentials = vault.RetrieveAll();
     if (credentials.Count == 0) return null;
     foreach (var credential in credentials)
     {
         if (credential.UserName == resource + username)
         {
             credential.RetrievePassword();
             return credential.Password;
         }
     }
     return null;
 }
        private void Read_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Read a credential from PasswordVault by supplying resource or username
                Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
                IReadOnlyList <PasswordCredential>         creds = null;
                PasswordCredential cred = null;

                //If both resource and username are empty, you can use RetrieveAll() to enumerate all credentials
                if (InputUserNameValue.Text == "" && InputResourceValue.Text == "")
                {
                    rootPage.NotifyUser("Retrieving all credentials since resource or username are not specified.", NotifyType.StatusMessage);
                    creds = vault.RetrieveAll();
                }

                //If there is only resouce, you can use FindAllByResource() to enumerate by resource.
                //Note: the password will not be returned, you need to call retrieveAll with returned resouce and username to get the credential with password
                else if (InputUserNameValue.Text == "")
                {
                    rootPage.NotifyUser("Retrieve credentials by resouces that you provided", NotifyType.StatusMessage);
                    creds = vault.FindAllByResource(InputResourceValue.Text);
                }

                //If there is only username, you can use findbyusername() to enumerate by resource.
                //Note: the password will not be returned, you need to call retrieveAll with returned resouce and username to get the credential with password
                else if (InputResourceValue.Text == "")
                {
                    rootPage.NotifyUser("Retrieve credentials by username that you provided", NotifyType.StatusMessage);
                    creds = vault.FindAllByUserName(InputUserNameValue.Text);
                }

                //Read by explicit resource and username name, result will be a single credential if it exists. Password will be returned.
                else
                {
                    cred = vault.Retrieve(InputResourceValue.Text, InputUserNameValue.Text);
                }

                //Output credential added to debug spew
                if (creds != null)
                {
                    rootPage.NotifyUser("There are " + creds.Count + " credential(s) found.", NotifyType.StatusMessage);
                    foreach (PasswordCredential c in creds)
                    {
                        try
                        {
                            PasswordCredential c1 = vault.Retrieve(c.Resource.ToString(), c.UserName.ToString());
                            rootPage.NotifyUser("Credential read successfully. " + "Resource: " + c.Resource.ToString() + ", " + "Username: "******"Password: "******".", NotifyType.StatusMessage);
                        }
                        catch (Exception Error)
                        {
                            rootPage.NotifyUser(Error.Message, NotifyType.ErrorMessage);
                        }
                    }
                }

                else if (cred != null)
                {
                    rootPage.NotifyUser("Credential read successfully. " + "Resource: " + cred.Resource + ", " + "Username: "******"Password: "******".", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser("Credential not found.", NotifyType.StatusMessage);
                }
            }
            catch (Exception Error)
            {
                if (Error.HResult == -2147023728)
                {
                    rootPage.NotifyUser("Credential not found.", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser(Error.Message, NotifyType.ErrorMessage);
                }
            }
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Attempt to send the calls to deregister the user. Will silently fail if there are
        /// networking issues.
        /// </summary>
        /// <returns></returns>
        public static async Task TryDeleteNotificationAsync()
        {
            try
            {
                await MobileService.GetPush().UnregisterNativeAsync();

                // Mobile Services doesn't have an API injection point for unregistering a push (just registering)
                await MobileService.InvokeApiAsync("unregister", HttpMethod.Get, null);
            }
            catch (MobileServiceInvalidOperationException)
            {
                // We'll see the errors on the server
            }

            MobileService.Logout();

            PasswordVault vault = new PasswordVault();
            
            foreach (PasswordCredential cred in vault.RetrieveAll())
            {
                vault.Remove(cred);
            }
        }
Ejemplo n.º 39
0
        void MainPage_AccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
         
            // Callback invoked to request the app for accounts when the accounts flyout is about to be displayed
            // Get the Deferral object and do some async operation if needed           
            var Deferral = args.GetDeferral();

            // do some async operation 
            //Uri uri = new Uri("ms-appx:///Assets/Smalllogo.png");
            //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);

  
            // Add CredLocker Credentials     
            CredentialCommandCredentialDeletedHandler credDeletedHandler = new CredentialCommandCredentialDeletedHandler(CredentialDeletedHandler);

            Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
            IReadOnlyList<PasswordCredential> creds = vault.RetrieveAll();

            if (creds.Count == 0)
                args.HeaderText = "There is not credential saved by the sample app, please go to Scenario 1 and add some credential, then try again.";
            else
                args.HeaderText = "Here are the credentials saved by sample app in Scenario 1.";

            foreach (PasswordCredential c in creds)
            {
                try
                {
                    CredentialCommand credCommand1 = new CredentialCommand(c, credDeletedHandler);
                    // Deleted is invoked after the system deletes the credential
                    args.CredentialCommands.Add(credCommand1);
                }
                catch (Exception Error) // Stored credential was deleted
                {
                    DebugPrint(Error.ToString());
                }
            }

            try
            {
                // Add Global commands     
                Object commandID = 1;
                UICommandInvokedHandler appCmdInvokedHandler = new UICommandInvokedHandler(CommandInvokedHandler);

                // SettingsCommand is an existing WinRT class used in the SettingsPane
                SettingsCommand command = new SettingsCommand(
                                                    commandID,
                                                    "App Specific Command Label...",
                                                    appCmdInvokedHandler);
                args.Commands.Add(command);
                // Add more commands here
            }
            catch (Exception Error) // No stored credentials, so none to delete
            {
                DebugPrint(Error.Message);
            }

            // Complete the Deferral()
            Deferral.Complete();
        }