Пример #1
0
        public HmacSHA256KeyGenerator()
        {
            string key;
            string salt;

            var authStorageHelper = AuthStorageHelper.GetAuthStorageHelper();

            if (!authStorageHelper.TryRetrieveEncryptionSettings(out key, out salt))
            {
                GenerateRandomPasswordAndSalt(out key, out salt);
                authStorageHelper.PersistEncryptionSettings(key, salt);
            }
            _key  = key;
            _salt = salt;
        }
Пример #2
0
        public HmacSHA256KeyGenerator(string hashAlgorithmName)
        {
            string password;
            string salt;

            var authStorageHelper = AuthStorageHelper.GetAuthStorageHelper();

            if (!authStorageHelper.TryRetrieveEncryptionSettings(out password, out salt))
            {
                GenerateRandomPasswordAndSalt(out password, out salt);
                authStorageHelper.PersistEncryptionSettings(password, salt);
            }
            Password           = password;
            Salt               = salt;
            HashAlgorithmNames = hashAlgorithmName;
        }
        /// <summary>
        ///     Returns a RestClient if user is already authenticated or null
        /// </summary>
        /// <returns></returns>
        public RestClient PeekRestClient()
        {
            Account account = AccountManager.GetAccount();

            if (account != null)
            {
                return(new RestClient(account.InstanceUrl, account.AccessToken,
                                      async() =>
                {
                    account = AccountManager.GetAccount();
                    AuthResponse authResponse =
                        await OAuth2.RefreshAuthTokenRequest(account.GetLoginOptions(), account.RefreshToken);
                    account.AccessToken = authResponse.AccessToken;
                    AuthStorageHelper.GetAuthStorageHelper().PersistCredentials(account);
                    return account.AccessToken;
                }
                                      ));
            }
            return(null);
        }
Пример #4
0
 /// <summary>
 ///     Returns a RestClient if user is already authenticated or null
 /// </summary>
 /// <returns></returns>
 public RestClient PeekRestClient(Account account = null)
 {
     if (account == null)
     {
         account = AccountManager.GetAccount();
     }
     if (account != null)
     {
         return(new RestClient(account.InstanceUrl, account.AccessToken,
                               async() =>
         {
             account = AccountManager.GetAccount();
             AuthResponse authResponse = await OAuth2.RefreshAuthTokenRequest(account.GetLoginOptions(), account.RefreshToken);
             account.AccessToken = authResponse.AccessToken;
             AuthStorageHelper.GetAuthStorageHelper().PersistCredentials(account);
             return account.AccessToken;
         }
                               ));
     }
     System.Diagnostics.Debug.WriteLine("PeekRestClient could not get RestClient");
     return(null);
 }