Пример #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);
 }
        private void SetupAccountPage()
        {
            ResourceLoader   loader       = ResourceLoader.GetForCurrentView("Salesforce.SDK.Universal/Resources");
            SalesforceConfig config       = SDKManager.ServerConfiguration;
            bool             titleMissing = true;

            if (!String.IsNullOrWhiteSpace(config.ApplicationTitle) && config.IsApplicationTitleVisible)
            {
                ApplicationTitle.Visibility = Visibility.Visible;
                ApplicationTitle.Text       = config.ApplicationTitle;
                titleMissing = false;
            }
            else
            {
                ApplicationTitle.Visibility = Visibility.Collapsed;
            }

            if (config.LoginBackgroundLogo != null)
            {
                if (ApplicationLogo.Items != null)
                {
                    ApplicationLogo.Items.Clear();
                    ApplicationLogo.Items.Add(config.LoginBackgroundLogo);
                }
                if (titleMissing)
                {
                    var padding = new Thickness(10, 24, 10, 24);
                    ApplicationLogo.Margin = padding;
                }
            }

            // set background from config
            if (config.LoginBackgroundColor != SalesforceConfig.NoColor)
            {
                var color = Color.FromArgb((byte)(config.LoginBackgroundColor >> 24),
                                           (byte)(config.LoginBackgroundColor >> 16),
                                           (byte)(config.LoginBackgroundColor >> 8),
                                           (byte)(config.LoginBackgroundColor));
                var background = new SolidColorBrush(color);
                PageRoot.Background = background;
                Background          = background;
                // ServerFlyoutPanel.Background = background;
                //  AddServerFlyoutPanel.Background = background;
            }

            // set foreground from config
            if (config.LoginForegroundColor != SalesforceConfig.NoColor)
            {
                var color = Color.FromArgb((byte)(config.LoginForegroundColor >> 24),
                                           (byte)(config.LoginForegroundColor >> 16),
                                           (byte)(config.LoginForegroundColor >> 8),
                                           (byte)(config.LoginForegroundColor));
                var foreground = new SolidColorBrush(color);
                Foreground = foreground;
                ApplicationTitle.Foreground   = foreground;
                LoginToSalesforce.Foreground  = foreground;
                LoginToSalesforce.BorderBrush = foreground;
                ChooseConnection.Foreground   = foreground;
                ChooseConnection.BorderBrush  = foreground;
            }

            if (Accounts == null || Accounts.Length == 0)
            {
                _currentState = SingleUserViewState;
                SetLoginBarVisibility(Visibility.Collapsed);
                AuthStorageHelper.WipePincode();
                VisualStateManager.GoToState(this, SingleUserViewState, true);
            }
            else
            {
                _currentState = MultipleUserViewState;
                SetLoginBarVisibility(Visibility.Visible);
                ListTitle.Text = loader.GetString("select_account");
                VisualStateManager.GoToState(this, MultipleUserViewState, true);
            }
            ListboxServers.ItemsSource     = Servers;
            AccountsList.ItemsSource       = Accounts;
            ServerFlyout.Opening          += ServerFlyout_Opening;
            ServerFlyout.Closed           += ServerFlyout_Closed;
            AddServerFlyout.Opened        += AddServerFlyout_Opened;
            AddServerFlyout.Closed        += AddServerFlyout_Closed;
            AccountsList.SelectionChanged += accountsList_SelectionChanged;
            ListboxServers.SelectedValue   = null;
            HostName.PlaceholderText       = LocalizedStrings.GetString("name");
            HostAddress.PlaceholderText    = LocalizedStrings.GetString("address");
            AddConnection.Visibility       = (SDKManager.ServerConfiguration.AllowNewConnections
                ? Visibility.Visible
                : Visibility.Collapsed);
        }