From faa9b1a9f718827f2b59e004f90ca4e7e2c2f600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bispo?= Date: Sat, 5 Aug 2023 01:37:02 +0100 Subject: [PATCH] [PM-3313] Fix Android SSO Login (#2663) * [PM-3313] Catch exception on AuthPendingRequest * [PM-3313] Fix lock timeout action if user doesn't have a master password. * code format --- .../SettingsPage/SettingsPageViewModel.cs | 8 ++++---- src/Core/Services/StateService.cs | 17 +++++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs b/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs index 5a2f1c827..8a42efa82 100644 --- a/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs +++ b/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs @@ -131,13 +131,13 @@ namespace Bit.App.Pages _vaultTimeoutDisplayValue ??= _vaultTimeoutOptions.Where(o => o.Value == CustomVaultTimeoutValue).First().Key; var savedVaultTimeoutAction = await _vaultTimeoutService.GetVaultTimeoutAction(); - var action = savedVaultTimeoutAction ?? VaultTimeoutAction.Lock; - if (!_hasMasterPassword && savedVaultTimeoutAction == null) + var timeoutAction = savedVaultTimeoutAction ?? VaultTimeoutAction.Lock; + if (!_hasMasterPassword && timeoutAction == VaultTimeoutAction.Lock) { - action = VaultTimeoutAction.Logout; + timeoutAction = VaultTimeoutAction.Logout; await _vaultTimeoutService.SetVaultTimeoutOptionsAsync(_vaultTimeout, VaultTimeoutAction.Logout); } - _vaultTimeoutActionDisplayValue = _vaultTimeoutActionOptions.FirstOrDefault(o => o.Value == action).Key; + _vaultTimeoutActionDisplayValue = _vaultTimeoutActionOptions.FirstOrDefault(o => o.Value == timeoutAction).Key; if (await _policyService.PolicyAppliesToUser(PolicyType.MaximumVaultTimeout)) { diff --git a/src/Core/Services/StateService.cs b/src/Core/Services/StateService.cs index b57fa783e..ea032ea5d 100644 --- a/src/Core/Services/StateService.cs +++ b/src/Core/Services/StateService.cs @@ -1334,16 +1334,21 @@ namespace Bit.Core.Services public async Task GetPendingAdminAuthRequestAsync(string userId = null) { - var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, - await GetDefaultStorageOptionsAsync()); - return await _storageMediatorService.GetAsync(Constants.PendingAdminAuthRequest(reconciledOptions.UserId), true); + try + { + // GetAsync will throw an ArgumentException exception if there isn't a value to deserialize + return await _storageMediatorService.GetAsync(await ComposeKeyAsync(Constants.PendingAdminAuthRequest, userId), true); + } + catch (ArgumentException) + { + return null; + } + } public async Task SetPendingAdminAuthRequestAsync(PendingAdminAuthRequest value, string userId = null) { - var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, - await GetDefaultStorageOptionsAsync()); - await _storageMediatorService.SaveAsync(Constants.PendingAdminAuthRequest(reconciledOptions.UserId), value, true); + await _storageMediatorService.SaveAsync(await ComposeKeyAsync(Constants.PendingAdminAuthRequest, userId), value, true); } public ConfigResponse GetConfigs()