1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-15 07:43:37 +00:00

[PM-3381] Fix TDE login 2FA flow (#2678)

* [PM-3381] Check for vault lock on 2FA screen

* [PM-3381] Move logic to ViewModel

* [PM-3381] Fix null vm error
This commit is contained in:
André Bispo
2023-08-11 17:32:51 +01:00
committed by GitHub
parent 5f4cd62f66
commit 3f4892fcc8
2 changed files with 34 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ using Bit.App.Controls;
using Bit.App.Models; using Bit.App.Models;
using Bit.App.Utilities; using Bit.App.Utilities;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Services;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Xamarin.Forms; using Xamarin.Forms;
@@ -24,17 +25,19 @@ namespace Bit.App.Pages
{ {
InitializeComponent(); InitializeComponent();
SetActivityIndicator(); SetActivityIndicator();
_authingWithSso = authingWithSso ?? false;
_appOptions = appOptions; _appOptions = appOptions;
_orgIdentifier = orgIdentifier; _orgIdentifier = orgIdentifier;
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService"); _broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService"); _messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
_vm = BindingContext as TwoFactorPageViewModel; _vm = BindingContext as TwoFactorPageViewModel;
_vm.Page = this; _vm.Page = this;
_vm.AuthingWithSso = authingWithSso ?? false;
_vm.StartSetPasswordAction = () => _vm.StartSetPasswordAction = () =>
Device.BeginInvokeOnMainThread(async () => await StartSetPasswordAsync()); Device.BeginInvokeOnMainThread(async () => await StartSetPasswordAsync());
_vm.TwoFactorAuthSuccessAction = () => _vm.TwoFactorAuthSuccessAction = () =>
Device.BeginInvokeOnMainThread(async () => await TwoFactorAuthSuccessAsync()); Device.BeginInvokeOnMainThread(async () => await TwoFactorAuthSuccessToMainAsync());
_vm.LockAction = () =>
Device.BeginInvokeOnMainThread(TwoFactorAuthSuccessWithSSOLocked);
_vm.UpdateTempPasswordAction = _vm.UpdateTempPasswordAction =
() => Device.BeginInvokeOnMainThread(async () => await UpdateTempPasswordAsync()); () => Device.BeginInvokeOnMainThread(async () => await UpdateTempPasswordAsync());
_vm.StartDeviceApprovalOptionsAction = _vm.StartDeviceApprovalOptionsAction =
@@ -188,13 +191,12 @@ namespace Bit.App.Pages
await Navigation.PushModalAsync(new NavigationPage(page)); await Navigation.PushModalAsync(new NavigationPage(page));
} }
private async Task TwoFactorAuthSuccessAsync() private void TwoFactorAuthSuccessWithSSOLocked()
{
if (_authingWithSso)
{ {
Application.Current.MainPage = new NavigationPage(new LockPage(_appOptions)); Application.Current.MainPage = new NavigationPage(new LockPage(_appOptions));
} }
else
private async Task TwoFactorAuthSuccessToMainAsync()
{ {
if (AppHelpers.SetAlternateMainPage(_appOptions)) if (AppHelpers.SetAlternateMainPage(_appOptions))
{ {
@@ -203,7 +205,6 @@ namespace Bit.App.Pages
var previousPage = await AppHelpers.ClearPreviousPage(); var previousPage = await AppHelpers.ClearPreviousPage();
Application.Current.MainPage = new TabsPage(_appOptions, previousPage); Application.Current.MainPage = new TabsPage(_appOptions, previousPage);
} }
}
private void Token_TextChanged(object sender, TextChangedEventArgs e) private void Token_TextChanged(object sender, TextChangedEventArgs e)
{ {

View File

@@ -33,6 +33,7 @@ namespace Bit.App.Pages
private readonly IStateService _stateService; private readonly IStateService _stateService;
private readonly II18nService _i18nService; private readonly II18nService _i18nService;
private readonly IAppIdService _appIdService; private readonly IAppIdService _appIdService;
private readonly IVaultTimeoutService _vaultTimeoutService;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IDeviceTrustCryptoService _deviceTrustCryptoService; private readonly IDeviceTrustCryptoService _deviceTrustCryptoService;
private TwoFactorProviderType? _selectedProviderType; private TwoFactorProviderType? _selectedProviderType;
@@ -55,6 +56,7 @@ namespace Bit.App.Pages
_stateService = ServiceContainer.Resolve<IStateService>("stateService"); _stateService = ServiceContainer.Resolve<IStateService>("stateService");
_i18nService = ServiceContainer.Resolve<II18nService>("i18nService"); _i18nService = ServiceContainer.Resolve<II18nService>("i18nService");
_appIdService = ServiceContainer.Resolve<IAppIdService>("appIdService"); _appIdService = ServiceContainer.Resolve<IAppIdService>("appIdService");
_vaultTimeoutService = ServiceContainer.Resolve<IVaultTimeoutService>();
_logger = ServiceContainer.Resolve<ILogger>(); _logger = ServiceContainer.Resolve<ILogger>();
_deviceTrustCryptoService = ServiceContainer.Resolve<IDeviceTrustCryptoService>(); _deviceTrustCryptoService = ServiceContainer.Resolve<IDeviceTrustCryptoService>();
@@ -71,6 +73,8 @@ namespace Bit.App.Pages
public bool Remember { get; set; } public bool Remember { get; set; }
public bool AuthingWithSso { get; set; }
public string Token { get; set; } public string Token { get; set; }
public bool DuoMethod => SelectedProviderType == TwoFactorProviderType.Duo || public bool DuoMethod => SelectedProviderType == TwoFactorProviderType.Duo ||
@@ -120,6 +124,7 @@ namespace Bit.App.Pages
public Command SubmitCommand { get; } public Command SubmitCommand { get; }
public ICommand MoreCommand { get; } public ICommand MoreCommand { get; }
public Action TwoFactorAuthSuccessAction { get; set; } public Action TwoFactorAuthSuccessAction { get; set; }
public Action LockAction { get; set; }
public Action StartDeviceApprovalOptionsAction { get; set; } public Action StartDeviceApprovalOptionsAction { get; set; }
public Action StartSetPasswordAction { get; set; } public Action StartSetPasswordAction { get; set; }
public Action CloseAction { get; set; } public Action CloseAction { get; set; }
@@ -344,7 +349,7 @@ namespace Bit.App.Pages
} }
else if (await _deviceTrustCryptoService.IsDeviceTrustedAsync()) else if (await _deviceTrustCryptoService.IsDeviceTrustedAsync())
{ {
TwoFactorAuthSuccessAction?.Invoke(); await TwoFactorAuthSuccessAsync();
} }
else else
{ {
@@ -353,7 +358,7 @@ namespace Bit.App.Pages
} }
else else
{ {
TwoFactorAuthSuccessAction?.Invoke(); await TwoFactorAuthSuccessAsync();
} }
} }
catch (ApiException e) catch (ApiException e)
@@ -447,5 +452,17 @@ namespace Bit.App.Pages
return false; return false;
} }
} }
public async Task TwoFactorAuthSuccessAsync()
{
if (AuthingWithSso && await _vaultTimeoutService.IsLockedAsync())
{
LockAction?.Invoke();
}
else
{
TwoFactorAuthSuccessAction?.Invoke();
}
}
} }
} }