mirror of
https://github.com/bitwarden/android.git
synced 2024-12-26 02:48:29 +03:00
[SG-773][SG-775] Duplicate passwordless login requests (#2160)
* [SG-773] Change method call to message send * [SG-773] Introduce lock to avoid concurrent executions of login requests * [SG-773][SG-775] add comment * [SSG-773][SG-775] Refactor passwordlessLoginRequest string to constant
This commit is contained in:
parent
a8909a3ce6
commit
9baa79e10b
3 changed files with 18 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bit.App.Abstractions;
|
using Bit.App.Abstractions;
|
||||||
using Bit.App.Models;
|
using Bit.App.Models;
|
||||||
|
@ -33,8 +34,9 @@ namespace Bit.App
|
||||||
private readonly IAccountsManager _accountsManager;
|
private readonly IAccountsManager _accountsManager;
|
||||||
private readonly IPushNotificationService _pushNotificationService;
|
private readonly IPushNotificationService _pushNotificationService;
|
||||||
private static bool _isResumed;
|
private static bool _isResumed;
|
||||||
// this variable is static because the app is launching new activities on notification click, creating new instances of App.
|
// these variables are static because the app is launching new activities on notification click, creating new instances of App.
|
||||||
private static bool _pendingCheckPasswordlessLoginRequests;
|
private static bool _pendingCheckPasswordlessLoginRequests;
|
||||||
|
private static object _processingLoginRequestLock = new object();
|
||||||
|
|
||||||
public App(AppOptions appOptions)
|
public App(AppOptions appOptions)
|
||||||
{
|
{
|
||||||
|
@ -143,9 +145,13 @@ namespace Bit.App
|
||||||
new NavigationPage(new RemoveMasterPasswordPage()));
|
new NavigationPage(new RemoveMasterPasswordPage()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (message.Command == "passwordlessLoginRequest" || message.Command == "unlocked" || message.Command == AccountsManagerMessageCommands.ACCOUNT_SWITCH_COMPLETED)
|
else if (message.Command == Constants.PasswordlessLoginRequestKey || message.Command == "unlocked" || message.Command == AccountsManagerMessageCommands.ACCOUNT_SWITCH_COMPLETED)
|
||||||
{
|
{
|
||||||
CheckPasswordlessLoginRequestsAsync().FireAndForget();
|
lock (_processingLoginRequestLock)
|
||||||
|
{
|
||||||
|
// lock doesn't allow for async execution
|
||||||
|
CheckPasswordlessLoginRequestsAsync().Wait();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -162,7 +168,6 @@ namespace Bit.App
|
||||||
_pendingCheckPasswordlessLoginRequests = true;
|
_pendingCheckPasswordlessLoginRequests = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_pendingCheckPasswordlessLoginRequests = false;
|
_pendingCheckPasswordlessLoginRequests = false;
|
||||||
if (await _vaultTimeoutService.IsLockedAsync())
|
if (await _vaultTimeoutService.IsLockedAsync())
|
||||||
{
|
{
|
||||||
|
@ -182,6 +187,11 @@ namespace Bit.App
|
||||||
|
|
||||||
// Delay to wait for the vault page to appear
|
// Delay to wait for the vault page to appear
|
||||||
await Task.Delay(2000);
|
await Task.Delay(2000);
|
||||||
|
// if there is a request modal opened ignore all incoming requests
|
||||||
|
if (App.Current.MainPage.Navigation.ModalStack.Any(p => p is NavigationPage navPage && navPage.CurrentPage is LoginPasswordlessPage))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
var loginRequestData = await _authService.GetPasswordlessLoginRequestByIdAsync(notification.Id);
|
var loginRequestData = await _authService.GetPasswordlessLoginRequestByIdAsync(notification.Id);
|
||||||
var page = new LoginPasswordlessPage(new LoginPasswordlessDetails()
|
var page = new LoginPasswordlessPage(new LoginPasswordlessDetails()
|
||||||
{
|
{
|
||||||
|
@ -242,7 +252,7 @@ namespace Bit.App
|
||||||
}
|
}
|
||||||
if (_pendingCheckPasswordlessLoginRequests)
|
if (_pendingCheckPasswordlessLoginRequests)
|
||||||
{
|
{
|
||||||
CheckPasswordlessLoginRequestsAsync().FireAndForget();
|
_messagingService.Send(Constants.PasswordlessLoginRequestKey);
|
||||||
}
|
}
|
||||||
if (Device.RuntimePlatform == Device.Android)
|
if (Device.RuntimePlatform == Device.Android)
|
||||||
{
|
{
|
||||||
|
@ -278,7 +288,7 @@ namespace Bit.App
|
||||||
_isResumed = true;
|
_isResumed = true;
|
||||||
if (_pendingCheckPasswordlessLoginRequests)
|
if (_pendingCheckPasswordlessLoginRequests)
|
||||||
{
|
{
|
||||||
CheckPasswordlessLoginRequestsAsync().FireAndForget();
|
_messagingService.Send(Constants.PasswordlessLoginRequestKey);
|
||||||
}
|
}
|
||||||
if (Device.RuntimePlatform == Device.Android)
|
if (Device.RuntimePlatform == Device.Android)
|
||||||
{
|
{
|
||||||
|
|
|
@ -157,7 +157,7 @@ namespace Bit.App.Services
|
||||||
};
|
};
|
||||||
|
|
||||||
_pushNotificationService.Value.SendLocalNotification(AppResources.LogInRequested, String.Format(AppResources.ConfimLogInAttempForX, userEmail), notificationData);
|
_pushNotificationService.Value.SendLocalNotification(AppResources.LogInRequested, String.Format(AppResources.ConfimLogInAttempForX, userEmail), notificationData);
|
||||||
_messagingService.Value.Send("passwordlessLoginRequest", passwordlessLoginMessage);
|
_messagingService.Value.Send(Constants.PasswordlessLoginRequestKey, passwordlessLoginMessage);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
public const string iOSNotificationClearActionId = "Clear";
|
public const string iOSNotificationClearActionId = "Clear";
|
||||||
public const string NotificationData = "notificationData";
|
public const string NotificationData = "notificationData";
|
||||||
public const string NotificationDataType = "Type";
|
public const string NotificationDataType = "Type";
|
||||||
|
public const string PasswordlessLoginRequestKey = "passwordlessLoginRequest";
|
||||||
public const int SelectFileRequestCode = 42;
|
public const int SelectFileRequestCode = 42;
|
||||||
public const int SelectFilePermissionRequestCode = 43;
|
public const int SelectFilePermissionRequestCode = 43;
|
||||||
public const int SaveFileRequestCode = 44;
|
public const int SaveFileRequestCode = 44;
|
||||||
|
|
Loading…
Reference in a new issue