mirror of
https://github.com/bitwarden/android.git
synced 2025-01-12 19:27:37 +03:00
[Captcha] Implement for 2fa (#1827)
This commit is contained in:
parent
79a76c4638
commit
fcc94d85af
3 changed files with 30 additions and 5 deletions
|
@ -17,7 +17,7 @@ using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
public class TwoFactorPageViewModel : BaseViewModel
|
public class TwoFactorPageViewModel : CaptchaProtectedViewModel
|
||||||
{
|
{
|
||||||
private readonly IDeviceActionService _deviceActionService;
|
private readonly IDeviceActionService _deviceActionService;
|
||||||
private readonly IAuthService _authService;
|
private readonly IAuthService _authService;
|
||||||
|
@ -28,6 +28,7 @@ namespace Bit.App.Pages
|
||||||
private readonly IMessagingService _messagingService;
|
private readonly IMessagingService _messagingService;
|
||||||
private readonly IBroadcasterService _broadcasterService;
|
private readonly IBroadcasterService _broadcasterService;
|
||||||
private readonly IStateService _stateService;
|
private readonly IStateService _stateService;
|
||||||
|
private readonly II18nService _i18nService;
|
||||||
|
|
||||||
private TwoFactorProviderType? _selectedProviderType;
|
private TwoFactorProviderType? _selectedProviderType;
|
||||||
private string _totpInstruction;
|
private string _totpInstruction;
|
||||||
|
@ -47,6 +48,7 @@ namespace Bit.App.Pages
|
||||||
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
||||||
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
||||||
_stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
_stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
||||||
|
_i18nService = ServiceContainer.Resolve<II18nService>("i18nService");
|
||||||
|
|
||||||
PageTitle = AppResources.TwoStepLogin;
|
PageTitle = AppResources.TwoStepLogin;
|
||||||
SubmitCommand = new Command(async () => await SubmitAsync());
|
SubmitCommand = new Command(async () => await SubmitAsync());
|
||||||
|
@ -112,6 +114,11 @@ namespace Bit.App.Pages
|
||||||
public Action CloseAction { get; set; }
|
public Action CloseAction { get; set; }
|
||||||
public Action UpdateTempPasswordAction { get; set; }
|
public Action UpdateTempPasswordAction { get; set; }
|
||||||
|
|
||||||
|
protected override II18nService i18nService => _i18nService;
|
||||||
|
protected override IEnvironmentService environmentService => _environmentService;
|
||||||
|
protected override IDeviceActionService deviceActionService => _deviceActionService;
|
||||||
|
protected override IPlatformUtilsService platformUtilsService => _platformUtilsService;
|
||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
if ((!_authService.AuthingWithSso() && !_authService.AuthingWithPassword()) ||
|
if ((!_authService.AuthingWithSso() && !_authService.AuthingWithPassword()) ||
|
||||||
|
@ -285,11 +292,24 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
await _deviceActionService.ShowLoadingAsync(AppResources.Validating);
|
await _deviceActionService.ShowLoadingAsync(AppResources.Validating);
|
||||||
}
|
}
|
||||||
var result = await _authService.LogInTwoFactorAsync(SelectedProviderType.Value, Token, Remember);
|
var result = await _authService.LogInTwoFactorAsync(SelectedProviderType.Value, Token, _captchaToken, Remember);
|
||||||
|
|
||||||
|
if (result.CaptchaNeeded)
|
||||||
|
{
|
||||||
|
if (await HandleCaptchaAsync(result.CaptchaSiteKey))
|
||||||
|
{
|
||||||
|
await SubmitAsync(false);
|
||||||
|
_captchaToken = null;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_captchaToken = null;
|
||||||
|
|
||||||
var task = Task.Run(() => _syncService.FullSyncAsync(true));
|
var task = Task.Run(() => _syncService.FullSyncAsync(true));
|
||||||
await _deviceActionService.HideLoadingAsync();
|
await _deviceActionService.HideLoadingAsync();
|
||||||
_messagingService.Send("listenYubiKeyOTP", false);
|
_messagingService.Send("listenYubiKeyOTP", false);
|
||||||
_broadcasterService.Unsubscribe(nameof(TwoFactorPage));
|
_broadcasterService.Unsubscribe(nameof(TwoFactorPage));
|
||||||
|
|
||||||
if (_authingWithSso && result.ResetMasterPassword)
|
if (_authingWithSso && result.ResetMasterPassword)
|
||||||
{
|
{
|
||||||
StartSetPasswordAction?.Invoke();
|
StartSetPasswordAction?.Invoke();
|
||||||
|
@ -305,6 +325,7 @@ namespace Bit.App.Pages
|
||||||
}
|
}
|
||||||
catch (ApiException e)
|
catch (ApiException e)
|
||||||
{
|
{
|
||||||
|
_captchaToken = null;
|
||||||
await _deviceActionService.HideLoadingAsync();
|
await _deviceActionService.HideLoadingAsync();
|
||||||
if (e?.Error != null)
|
if (e?.Error != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Bit.Core.Abstractions
|
||||||
Task<AuthResult> LogInAsync(string email, string masterPassword, string captchaToken);
|
Task<AuthResult> LogInAsync(string email, string masterPassword, string captchaToken);
|
||||||
Task<AuthResult> LogInSsoAsync(string code, string codeVerifier, string redirectUrl, string orgId);
|
Task<AuthResult> LogInSsoAsync(string code, string codeVerifier, string redirectUrl, string orgId);
|
||||||
Task<AuthResult> LogInCompleteAsync(string email, string masterPassword, TwoFactorProviderType twoFactorProvider, string twoFactorToken, bool? remember = null);
|
Task<AuthResult> LogInCompleteAsync(string email, string masterPassword, TwoFactorProviderType twoFactorProvider, string twoFactorToken, bool? remember = null);
|
||||||
Task<AuthResult> LogInTwoFactorAsync(TwoFactorProviderType twoFactorProvider, string twoFactorToken, bool? remember = null);
|
Task<AuthResult> LogInTwoFactorAsync(TwoFactorProviderType twoFactorProvider, string twoFactorToken, string captchaToken, bool? remember = null);
|
||||||
void LogOut(Action callback);
|
void LogOut(Action callback);
|
||||||
void Init();
|
void Init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,8 +141,12 @@ namespace Bit.Core.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<AuthResult> LogInTwoFactorAsync(TwoFactorProviderType twoFactorProvider, string twoFactorToken,
|
public Task<AuthResult> LogInTwoFactorAsync(TwoFactorProviderType twoFactorProvider, string twoFactorToken,
|
||||||
bool? remember = null)
|
string captchaToken, bool? remember = null)
|
||||||
{
|
{
|
||||||
|
if (captchaToken != null)
|
||||||
|
{
|
||||||
|
CaptchaToken = captchaToken;
|
||||||
|
}
|
||||||
return LogInHelperAsync(Email, MasterPasswordHash, LocalMasterPasswordHash, Code, CodeVerifier, SsoRedirectUrl, _key,
|
return LogInHelperAsync(Email, MasterPasswordHash, LocalMasterPasswordHash, Code, CodeVerifier, SsoRedirectUrl, _key,
|
||||||
twoFactorProvider, twoFactorToken, remember, CaptchaToken);
|
twoFactorProvider, twoFactorToken, remember, CaptchaToken);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue