Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add mobile unlock modal to web app allowing use from both login and unlock screens (#1347)

Leendert de Borst42524d14126a
diff --git a/apps/server/AliasVault.Client/Auth/Components/MobileUnlockModal.razor b/apps/server/AliasVault.Client/Auth/Components/MobileUnlockModal.razor
new file mode 100644
index 000000000..6c51bdb66
--- /dev/null
+++ b/apps/server/AliasVault.Client/Auth/Components/MobileUnlockModal.razor
@@ -0,0 +1,289 @@
+@using AliasVault.Client.Auth.Models
+@using AliasVault.Client.Auth.Services
+@using AliasVault.Client.Main.Components.Layout
+@using Microsoft.Extensions.Localization
+@using Microsoft.Extensions.DependencyInjection
+@implements IDisposable
+
+@if (IsOpen)
+{
+ <ModalWrapper>
+ <!-- Backdrop -->
+ <div class="fixed inset-0 bg-black bg-opacity-80 transition-opacity" @onclick="HandleClose"></div>
+
+ <!-- Modal -->
+ <div class="relative transform overflow-hidden rounded-lg bg-white dark:bg-gray-800 px-6 pb-6 pt-5 text-left shadow-xl transition-all w-full max-w-md mx-4">
+ <!-- Close button -->
+ <button type="button" class="absolute right-4 top-4 text-gray-400 hover:text-gray-500 focus:outline-none" @onclick="HandleClose">
+ <span class="sr-only">@SharedLocalizer["Close"]</span>
+ <svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
+ </svg>
+ </button>
+
+ <!-- Content -->
+ <div class="mt-3">
+ <h3 class="text-xl font-bold text-gray-900 dark:text-white mb-2">
+ @Title
+ </h3>
+ <p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
+ @Description
+ </p>
+
+ @if (!string.IsNullOrEmpty(_errorMessage))
+ {
+ <div class="mb-4 p-3 bg-red-100 dark:bg-red-900/30 border border-red-400 dark:border-red-700 rounded text-red-700 dark:text-red-400 text-sm">
+ @_errorMessage
+ </div>
+ }
+
+ @if (!string.IsNullOrEmpty(_qrCodeUrl))
+ {
+ <div class="flex flex-col items-center mb-4">
+ <div id="@_qrElementId" data-url="@_qrCodeUrl" class="@(_isLoading ? "hidden" : "") mb-3 p-4 bg-white rounded-lg border-4 border-gray-200 dark:border-gray-600">
+ <!-- QR code will be rendered here -->
+ </div>
+ @if (!_isLoading)
+ {
+ <div class="text-gray-700 dark:text-gray-300 text-sm font-medium">
+ @FormatTime(_timeRemaining)
+ </div>
+ }
+ </div>
+ }
+
+ @if (_isLoading && string.IsNullOrEmpty(_errorMessage))
+ {
+ <div class="flex justify-center py-8">
+ <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-primary-600"></div>
+ </div>
+ }
+
+ <button type="button" @onclick="HandleClose" class="mt-4 w-full inline-flex justify-center rounded-md bg-white dark:bg-gray-700 px-3 py-2 text-sm font-semibold text-gray-900 dark:text-gray-200 shadow-sm ring-1 ring-inset ring-gray-300 dark:ring-gray-600 hover:bg-gray-50 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-primary-500">
+ @SharedLocalizer["Cancel"]
+ </button>
+ </div>
+ </div>
+ </ModalWrapper>
+}
+
+@code {
+ private string? _qrCodeUrl;
+ private string? _errorMessage;
+ private int _timeRemaining = 120; // 2 minutes in seconds
+ private MobileLoginUtility? _mobileLoginUtility;
+ private bool _isLoading = true;
+ private System.Threading.Timer? _countdownTimer;
+ private string _qrElementId = $"mobile-unlock-qr-{Guid.NewGuid():N}";
+
+ [Inject]
+ private HttpClient Http { get; set; } = default!;
+
+ [Inject]
+ private JsInteropService JsInteropService { get; set; } = default!;
+
+ [Inject]
+ private ILogger<MobileUnlockModal> Logger { get; set; } = default!;
+
+ [Inject]
+ private IStringLocalizerFactory LocalizerFactory { get; set; } = default!;
+
+ [Inject]
+ private IServiceProvider ScopedServices { get; set; } = default!;
+
+ private IStringLocalizer SharedLocalizer => LocalizerFactory.Create("SharedResources", "AliasVault.Client");
+
+ /// <summary>
+ /// Whether the modal is open.
+ /// </summary>
+ [Parameter]
+ public bool IsOpen { get; set; }
+
+ /// <summary>
+ /// Callback when the modal is closed.
+ /// </summary>
+ [Parameter]
+ public EventCallback OnClose { get; set; }
+
+ /// <summary>
+ /// Callback when mobile login/unlock succeeds with the result.
+ /// </summary>
+ [Parameter]
+ public EventCallback<MobileLoginResult> OnSuccess { get; set; }
+
+ /// <summary>
+ /// Mode - 'login' or 'unlock'.
+ /// </summary>
+ [Parameter]
+ public string Mode { get; set; } = "login";
+
+ /// <summary>
+ /// Modal title based on mode.
+ /// </summary>
+ private string Title => Mode == "unlock"
+ ? LocalizerFactory.Create("Pages.Auth.MobileUnlockModal", "AliasVault.Client")["UnlockTitle"]
+ : LocalizerFactory.Create("Pages.Auth.MobileUnlockModal", "AliasVault.Client")["PageTitle"];
+
+ /// <summary>
+ /// Modal description based on mode.
+ /// </summary>
+ private string Description => LocalizerFactory.Create("Pages.Auth.MobileUnlockModal", "AliasVault.Client")["ScanQrCodeDescription"];
+
+ /// <inheritdoc />
+ protected override async Task OnParametersSetAsync()
+ {
+ await base.OnParametersSetAsync();
+
+ if (IsOpen && _mobileLoginUtility == null)
+ {
+ await InitiateMobileLoginAsync();
+ }
+ else if (!IsOpen)
+ {
+ Cleanup();
+ }
+ }
+
+ /// <summary>
+ /// Initialize mobile login when modal opens.
+ /// </summary>
+ private async Task InitiateMobileLoginAsync()
+ {
+ try
+ {
+ _isLoading = true;
+ _errorMessage = null;
+ _qrCodeUrl = null;
+ _timeRemaining = 120;
+ StateHasChanged();
+
+ // Initialize mobile login utility
+ var utilityLogger = ScopedServices.GetRequiredService<ILogger<MobileLoginUtility>>();
+ _mobileLoginUtility = new MobileLoginUtility(Http, JsInteropService, utilityLogger);
+
+ // Initiate mobile login and get QR code data
+ var requestId = await _mobileLoginUtility.InitiateAsync();
+
+ // Generate QR code with AliasVault prefix for mobile login
+ _qrCodeUrl = $"aliasvault://mobile-login/{requestId}";
+
+ // Render QR code while showing loading
+ StateHasChanged();
+ await Task.Delay(100); // Give DOM time to render
+ await JsInteropService.GenerateQrCode(_qrElementId);
+
+ // Wait for QR code to be fully rendered before hiding loading
+ await Task.Delay(300);
+
+ _isLoading = false;
+ StateHasChanged();
+
+ // Start countdown timer
+ StartCountdownTimer();
+
+ // Start polling for response
+ await _mobileLoginUtility.StartPollingAsync(
+ HandleSuccessAsync,
+ HandleErrorAsync);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex, "Error initiating mobile login");
+ _isLoading = false;
+ _errorMessage = SharedLocalizer["ErrorUnknown"];
+ StateHasChanged();
+ }
+ }
+
+ /// <summary>
+ /// Handle successful mobile login/unlock.
+ /// </summary>
+ private async Task HandleSuccessAsync(MobileLoginResult result)
+ {
+ try
+ {
+ // Call parent success callback
+ await OnSuccess.InvokeAsync(result);
+
+ // Close modal after successful processing
+ await HandleClose();
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex, "Error handling mobile login success");
+ _errorMessage = SharedLocalizer["ErrorUnknown"];
+ StateHasChanged();
+ }
+ }
+
+ /// <summary>
+ /// Handle error.
+ /// </summary>
+ private void HandleErrorAsync(string errorMessage)
+ {
+ _isLoading = false;
+ _errorMessage = errorMessage;
+ StateHasChanged();
+ }
+
+ /// <summary>
+ /// Handle modal close.
+ /// </summary>
+ private async Task HandleClose()
+ {
+ Cleanup();
+ await OnClose.InvokeAsync();
+ }
+
+ /// <summary>
+ /// Cleanup resources.
+ /// </summary>
+ private void Cleanup()
+ {
+ _mobileLoginUtility?.Cleanup();
+ _mobileLoginUtility?.Dispose();
+ _mobileLoginUtility = null;
+ _countdownTimer?.Dispose();
+ _countdownTimer = null;
+ _qrCodeUrl = null;
+ _errorMessage = null;
+ _timeRemaining = 120;
+ _isLoading = true;
+ }
+
+ /// <summary>
+ /// Format time remaining as MM:SS.
+ /// </summary>
+ private string FormatTime(int seconds)
+ {
+ var mins = seconds / 60;
+ var secs = seconds % 60;
+ return $"{mins}:{secs:D2}";
+ }
+
+ /// <summary>
+ /// Start countdown timer.
+ /// </summary>
+ private void StartCountdownTimer()
+ {
+ _countdownTimer = new System.Threading.Timer(_ =>
+ {
+ if (_timeRemaining > 0)
+ {
+ _timeRemaining--;
+ InvokeAsync(StateHasChanged);
+ }
+ else
+ {
+ _countdownTimer?.Dispose();
+ _mobileLoginUtility?.StopPolling();
+ }
+ }, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
+ }
+
+ /// <inheritdoc />
+ public void Dispose()
+ {
+ Cleanup();
+ }
+}
diff --git a/apps/server/AliasVault.Client/Auth/Pages/Login.razor b/apps/server/AliasVault.Client/Auth/Pages/Login.razor
index f4ea0f380..48b38479a 100644
--- a/apps/server/AliasVault.Client/Auth/Pages/Login.razor
+++ b/apps/server/AliasVault.Client/Auth/Pages/Login.razor
@@ -112,25 +112,18 @@ else
<a href="/user/forgot-password" class="ml-auto text-sm text-primary-700 hover:underline dark:text-primary-500">@Localizer["LostPasswordLink"]</a>
</div>
- <button type="submit" class="w-full px-5 py-2 text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800 flex items-center justify-center gap-2">
- @Localizer["LoginButton"]
- </button>
-
- <div class="relative hidden md:block">
- <div class="absolute inset-0 flex items-center">
- <div class="w-full border-t border-gray-300 dark:border-gray-600"></div>
- </div>
- <div class="relative flex justify-center text-sm">
- <span class="px-2 text-gray-500 bg-white dark:bg-gray-800 dark:text-gray-400">@SharedLocalizer["Or"]</span>
- </div>
+ <div class="flex flex-col gap-4">
+ <button type="submit" class="w-full px-5 py-2 text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800 flex items-center justify-center gap-2">
+ @Localizer["LoginButton"]
+ </button>
+ <button type="button" @onclick="() => _showMobileLoginModal = true" class="hidden md:flex w-full px-5 py-2 text-base font-medium text-center text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-100 focus:ring-4 focus:ring-gray-200 dark:bg-gray-700 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:ring-gray-700 items-center justify-center gap-2">
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z"></path>
+ </svg>
+ @Localizer["MobileDeviceLink"]
+ </button>
</div>
- <a href="/user/mobile-login" class="hidden md:flex w-full px-5 py-2 text-base font-medium text-center text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-100 focus:ring-4 focus:ring-gray-200 dark:bg-gray-700 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:ring-gray-700 items-center justify-center gap-2">
- <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z"></path>
- </svg>
- @Localizer["MobileDeviceLink"]
- </a>
@if (Config.PublicRegistrationEnabled)
{
@@ -143,6 +136,11 @@ else
<FooterLogin />
+<MobileUnlockModal IsOpen="@_showMobileLoginModal"
+ OnClose="() => _showMobileLoginModal = false"
+ OnSuccess="HandleMobileLoginSuccess"
+ Mode="login" />
+
@code {
private readonly LoginFormModel _loginModel = new();
private readonly LoginModel2Fa _loginModel2Fa = new();
@@ -151,6 +149,7 @@ else
private ServerValidationErrors _serverValidationErrors = new();
private bool _showTwoFactorAuthStep;
private bool _showLoginWithRecoveryCodeStep;
+ private bool _showMobileLoginModal;
private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Auth.Login", "AliasVault.Client");
private IStringLocalizer ApiErrorLocalizer => LocalizerFactory.Create("ApiErrors", "AliasVault.Client");
@@ -475,4 +474,78 @@ else
}
}
+ /// <summary>
+ /// Handle successful mobile login.
+ /// </summary>
+ private async Task HandleMobileLoginSuccess(MobileLoginResult result)
+ {
+ _loadingIndicator.Show(Localizer["LoggingInMessage"]);
+ _serverValidationErrors.Clear();
+
+ try
+ {
+ // Clear global messages
+ GlobalNotificationService.ClearMessages();
+
+ // Call /login endpoint to retrieve salt and encryption settings
+ var loginInitiateRequest = new { username = result.Username };
+ var loginResponse = await Http.PostAsJsonAsync("v1/Auth/login", loginInitiateRequest);
+
+ if (!loginResponse.IsSuccessStatusCode)
+ {
+ _serverValidationErrors.AddError(Localizer["LoginErrorMessage"]);
+ return;
+ }
+
+ var loginData = await loginResponse.Content.ReadFromJsonAsync<LoginInitiateResponse>();
+ if (loginData == null)
+ {
+ _serverValidationErrors.AddError(Localizer["LoginErrorMessage"]);
+ return;
+ }
+
+ // Store the tokens in local storage
+ await AuthService.StoreAccessTokenAsync(result.Token);
+ await AuthService.StoreRefreshTokenAsync(result.RefreshToken);
+
+ // Convert decryption key from base64 string to byte array
+ var decryptionKeyBytes = Convert.FromBase64String(result.DecryptionKey);
+
+ // Store the encryption key in memory
+ await AuthService.StoreEncryptionKeyAsync(decryptionKeyBytes);
+
+ await AuthStateProvider.GetAuthenticationStateAsync();
+ GlobalNotificationService.ClearMessages();
+
+ // Redirect to the page the user was trying to access before if set
+ var localStorageReturnUrl = await LocalStorage.GetItemAsync<string>(ReturnUrlKey);
+ if (!string.IsNullOrEmpty(localStorageReturnUrl))
+ {
+ await LocalStorage.RemoveItemAsync(ReturnUrlKey);
+ NavigationManager.NavigateTo(localStorageReturnUrl);
+ }
+ else
+ {
+ NavigationManager.NavigateTo("/");
+ }
+ }
+#if DEBUG
+ catch (Exception ex)
+ {
+ // If in debug mode show the actual exception.
+ _serverValidationErrors.AddError(ex.ToString());
+ }
+#else
+ catch
+ {
+ // If in release mode show a generic error.
+ _serverValidationErrors.AddError(Localizer["LoginErrorMessage"]);
+ }
+#endif
+ finally
+ {
+ _loadingIndicator.Hide();
+ }
+ }
+
}
diff --git a/apps/server/AliasVault.Client/Auth/Pages/MobileLogin.razor b/apps/server/AliasVault.Client/Auth/Pages/MobileLogin.razor
deleted file mode 100644
index 781010b30..000000000
--- a/apps/server/AliasVault.Client/Auth/Pages/MobileLogin.razor
+++ /dev/null
@@ -1,266 +0,0 @@
-@page "/user/mobile-login"
-@inherits AliasVault.Client.Auth.Pages.Base.LoginBase
-@layout Auth.Layout.MainLayout
-@attribute [AllowAnonymous]
-@using System.Text.Json
-@using AliasVault.Client.Auth.Components
-@using AliasVault.Client.Auth.Models
-@using AliasVault.Client.Auth.Services
-@using AliasVault.Client.Utilities
-@using AliasVault.Cryptography.Client
-@using AliasVault.Shared.Models.WebApi.Auth
-@using Microsoft.Extensions.Localization
-@implements IDisposable
-
-<h2 class="text-2xl font-bold text-gray-900 dark:text-white mb-4">
- @Localizer["PageTitle"]
-</h2>
-
-@if (!string.IsNullOrEmpty(_errorMessage))
-{
- <div class="mb-4 p-4 text-sm text-red-800 rounded-lg bg-red-50 dark:bg-gray-800 dark:text-red-400">
- @_errorMessage
- </div>
-}
-
-<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm">
- <p class="text-gray-700 dark:text-gray-300 mb-6">
- @Localizer["ScanQrCodeDescription"]
- </p>
-
- <div class="flex flex-col items-center mb-6">
- @if (_isLoading)
- {
- <SmallLoadingIndicator />
- }
-
- @if (!string.IsNullOrEmpty(_qrCodeUrl))
- {
- <div id="mobile-login-qr" data-url="@_qrCodeUrl" class="@(_isLoading ? "hidden" : "") mb-4 p-4 bg-white rounded-lg border-4 border-gray-200 dark:border-gray-600">
- <!-- QR code will be rendered here -->
- </div>
- @if (!_isLoading)
- {
- <div class="text-gray-700 dark:text-gray-300 text-sm">
- @FormatTime(_timeRemaining)
- </div>
- }
- }
- </div>
-
- <div class="flex w-full">
- <button type="button" @onclick="HandleCancel" class="w-full text-gray-900 bg-white border border-gray-300 focus:outline-none hover:bg-gray-100 focus:ring-4 focus:ring-gray-200 font-medium rounded-lg text-sm px-5 py-2.5 dark:bg-gray-800 dark:text-white dark:border-gray-600 dark:hover:bg-gray-700 dark:hover:border-gray-600 dark:focus:ring-gray-700">
- @SharedLocalizer["Cancel"]
- </button>
- </div>
-</div>
-
-<FooterLogin />
-
-@code {
- private string? _qrCodeUrl;
- private string? _errorMessage;
- private int _timeRemaining = 120; // 2 minutes in seconds
- private MobileLoginUtility? _mobileLoginUtility;
- private bool _isLoading = true;
- private System.Threading.Timer? _countdownTimer;
-
- private IStringLocalizer Localizer => LocalizerFactory.Create("Pages.Auth.MobileLogin", "AliasVault.Client");
- private IStringLocalizer ApiErrorLocalizer => LocalizerFactory.Create("ApiErrors", "AliasVault.Client");
- private IStringLocalizer SharedLocalizer => LocalizerFactory.Create("SharedResources", "AliasVault.Client");
-
- /// <inheritdoc />
- protected override async Task OnInitializedAsync()
- {
- await base.OnInitializedAsync();
-
- // Check if already authenticated
- var authState = await AuthStateProvider.GetAuthenticationStateAsync();
- if (authState.User.Identity?.IsAuthenticated == true)
- {
- NavigationManager.NavigateTo("/");
- return;
- }
- }
-
- /// <inheritdoc />
- protected override async Task OnAfterRenderAsync(bool firstRender)
- {
- await base.OnAfterRenderAsync(firstRender);
-
- if (firstRender)
- {
- await InitiateMobileLoginAsync();
- }
- }
-
- /// <summary>
- /// Initialize mobile login on component mount.
- /// </summary>
- private async Task InitiateMobileLoginAsync()
- {
- try
- {
- _isLoading = true;
- _errorMessage = null;
- StateHasChanged();
-
- // Initialize mobile login utility
- _mobileLoginUtility = new MobileLoginUtility(Http, JsInteropService, ScopedServices.GetRequiredService<ILogger<MobileLoginUtility>>());
-
- // Initiate mobile login and get QR code data
- var requestId = await _mobileLoginUtility.InitiateAsync();
-
- // Generate QR code with AliasVault prefix for mobile login
- _qrCodeUrl = $"aliasvault://mobile-login/{requestId}";
-
- // Render QR code first while still showing loading animation
- StateHasChanged();
- await Task.Delay(100); // Give DOM time to render
- await JsInteropService.GenerateQrCode("mobile-login-qr");
-
- // Wait for QR code to be fully rendered before hiding loading animation
- await Task.Delay(300);
-
- _isLoading = false;
- StateHasChanged();
-
- // Start countdown timer
- StartCountdownTimer();
-
- // Start polling for response
- await _mobileLoginUtility.StartPollingAsync(
- HandleSuccessfulAuthAsync,
- HandleErrorAsync);
- }
- catch (Exception)
- {
- _isLoading = false;
- _errorMessage = SharedLocalizer["ErrorUnknown"];
- StateHasChanged();
- }
- }
-
- /// <summary>
- /// Handle successful authentication from mobile login.
- /// </summary>
- /// <param name="result">The decrypted mobile login result containing authentication data.</param>
- private async Task HandleSuccessfulAuthAsync(MobileLoginResult result)
- {
- try
- {
- _isLoading = true;
- _qrCodeUrl = null;
- StateHasChanged();
-
- // Call /login endpoint to retrieve salt and encryption settings
- var loginInitiateRequest = new { username = result.Username };
- var loginResponse = await Http.PostAsJsonAsync("v1/Auth/login", loginInitiateRequest);
-
- if (!loginResponse.IsSuccessStatusCode)
- {
- _isLoading = false;
- _errorMessage = SharedLocalizer["ErrorUnknown"];
- StateHasChanged();
- return;
- }
-
- var loginData = await loginResponse.Content.ReadFromJsonAsync<LoginInitiateResponse>();
- if (loginData == null)
- {
- _isLoading = false;
- _errorMessage = SharedLocalizer["ErrorUnknown"];
- StateHasChanged();
- return;
- }
-
- // Store the tokens in local storage
- await AuthService.StoreAccessTokenAsync(result.Token);
- await AuthService.StoreRefreshTokenAsync(result.RefreshToken);
-
- // Convert decryption key from base64 string to byte array
- var decryptionKeyBytes = Convert.FromBase64String(result.DecryptionKey);
-
- // Store the encryption key in memory
- await AuthService.StoreEncryptionKeyAsync(decryptionKeyBytes);
-
- await AuthStateProvider.GetAuthenticationStateAsync();
- GlobalNotificationService.ClearMessages();
-
- // Redirect to the page the user was trying to access before if set
- var localStorageReturnUrl = await LocalStorage.GetItemAsync<string>(ReturnUrlKey);
- if (!string.IsNullOrEmpty(localStorageReturnUrl))
- {
- await LocalStorage.RemoveItemAsync(ReturnUrlKey);
- NavigationManager.NavigateTo(localStorageReturnUrl);
- }
- else
- {
- NavigationManager.NavigateTo("/");
- }
- }
- catch (Exception)
- {
- _isLoading = false;
- _errorMessage = SharedLocalizer["ErrorUnknown"];
- StateHasChanged();
- }
- }
-
- /// <summary>
- /// Handle error.
- /// </summary>
- private void HandleErrorAsync(string errorMessage)
- {
- _isLoading = false;
- _errorMessage = errorMessage;
- StateHasChanged();
- }
-
- /// <summary>
- /// Handle cancel button.
- /// </summary>
- private void HandleCancel()
- {
- _mobileLoginUtility?.Cleanup();
- _countdownTimer?.Dispose();
- NavigationManager.NavigateTo("/user/login");
- }
-
- /// <summary>
- /// Format time remaining as MM:SS.
- /// </summary>
- private string FormatTime(int seconds)
- {
- var mins = seconds / 60;
- var secs = seconds % 60;
- return $"{mins}:{secs:D2}";
- }
-
- /// <summary>
- /// Start countdown timer.
- /// </summary>
- private void StartCountdownTimer()
- {
- _countdownTimer = new System.Threading.Timer(_ =>
- {
- if (_timeRemaining > 0)
- {
- _timeRemaining--;
- InvokeAsync(StateHasChanged);
- }
- else
- {
- _countdownTimer?.Dispose();
- _mobileLoginUtility?.StopPolling();
- }
- }, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
- }
-
- /// <inheritdoc/>
- public void Dispose()
- {
- _mobileLoginUtility?.Dispose();
- _countdownTimer?.Dispose();
- }
-}
diff --git a/apps/server/AliasVault.Client/Auth/Pages/Unlock.razor b/apps/server/AliasVault.Client/Auth/Pages/Unlock.razor
index 6933c27f5..654669cb1 100644
--- a/apps/server/AliasVault.Client/Auth/Pages/Unlock.razor
+++ b/apps/server/AliasVault.Client/Auth/Pages/Unlock.razor
@@ -46,11 +46,11 @@ else
<ServerValidationErrors @ref="_serverValidationErrors" />
<div class="flex space-x-4">
- <button type="button" @onclick="UnlockWithWebAuthn" class="flex-grow inline-flex items-center justify-center px-5 py-3 text-base font-medium text-center text-white rounded-lg bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">
+ <button type="button" @onclick="UnlockWithWebAuthn" class="flex-grow inline-flex items-center justify-center px-5 py-2 text-base font-medium text-center text-white rounded-lg bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">
<svg class="w-5 h-5 mr-2 -ml-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M17.414 2.586a2 2 0 00-2.828 0L7 10.172V13h2.828l7.586-7.586a2 2 0 000-2.828z"></path><path fill-rule="evenodd" d="M2 6a2 2 0 012-2h4a1 1 0 010 2H4v10h10v-4a1 1 0 112 0v4a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" clip-rule="evenodd"></path></svg>
@Localizer["UnlockWithWebAuthn"]
</button>
- <button type="button" @onclick="async () => await ShowPasswordLogin()" class="inline-flex items-center justify-center px-5 py-3 text-base font-medium text-center text-gray-900 rounded-lg border border-gray-300 hover:bg-gray-100 focus:ring-4 focus:ring-gray-100 dark:text-white dark:border-gray-700 dark:hover:bg-gray-700 dark:focus:ring-gray-800">
+ <button type="button" @onclick="async () => await ShowPasswordLogin()" class="inline-flex items-center justify-center px-5 py-2 text-base font-medium text-center text-gray-900 rounded-lg border border-gray-300 hover:bg-gray-100 focus:ring-4 focus:ring-gray-100 dark:text-white dark:border-gray-700 dark:hover:bg-gray-700 dark:focus:ring-gray-800">
@Localizer["UnlockWithPassword"]
</button>
</div>
@@ -72,20 +72,31 @@ else
<ValidationMessage For="() => _unlockModel.Password"/>
</div>
- <button type="submit" class="w-full inline-flex items-center justify-center px-5 py-3 text-base font-medium text-center text-white rounded-lg bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">
- <svg class="w-5 h-5 mr-2 -ml-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10 2a5 5 0 00-5 5v2a2 2 0 00-2 2v5a2 2 0 002 2h10a2 2 0 002-2v-5a2 2 0 00-2-2H7V7a3 3 0 015.905-.75 1 1 0 001.937-.5A5.002 5.002 0 0010 2z"></path></svg>
+ <button type="submit" class="w-full px-5 py-2 text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800 flex items-center justify-center gap-2">
@Localizer["UnlockButton"]
</button>
</EditForm>
+
+ <button type="button" @onclick="() => _showMobileUnlockModal = true" class="hidden md:flex w-full px-5 py-2 text-base font-medium text-center text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-100 focus:ring-4 focus:ring-gray-200 dark:bg-gray-700 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:ring-gray-700 items-center justify-center gap-2 mt-4">
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z"></path>
+ </svg>
+ @Localizer["UnlockWithMobileButton"]
+ </button>
}
- <div class="text-sm font-medium text-gray-500 dark:text-gray-400 mt-6">
+ <div class="text-sm text-center font-medium text-gray-500 dark:text-gray-400 mt-6">
@Localizer["SwitchAccountsText"] <a href="/user/logout" class="text-primary-700 hover:underline dark:text-primary-500">@Localizer["LogOutLink"]</a>
</div>
}
<FooterLogin />
+<MobileUnlockModal IsOpen="@_showMobileUnlockModal"
+ OnClose="() => _showMobileUnlockModal = false"
+ OnSuccess="HandleMobileUnlockSuccess"
+ Mode="unlock" />
+
@code {
/// <summary>
/// Skip automatic WebAuthn unlock during page load if set to true.
@@ -98,12 +109,14 @@ else
private bool IsWebAuthnLoading { get; set; }
private bool ShowWebAuthnButton { get; set; }
private bool IsPasswordFocused { get; set; }
+ private bool _showMobileUnlockModal;
private readonly UnlockModel _unlockModel = new();
private FullScreenLoadingIndicator _loadingIndicator = new();
private ServerValidationErrors _serverValidationErrors = new();
private PasswordInputField? passwordField;
private IStringLocalizer Localizer => LocalizerFactory.Create("Pages.Auth.Unlock", "AliasVault.Client");
private IStringLocalizer ApiErrorLocalizer => LocalizerFactory.Create("ApiErrors", "AliasVault.Client");
+ private IStringLocalizer SharedLocalizer => LocalizerFactory.Create("SharedResources", "AliasVault.Client");
/// <inheritdoc />
protected override async Task OnAfterRenderAsync(bool firstRender)
@@ -353,4 +366,62 @@ else
// Do nothing
}
}
+
+ /// <summary>
+ /// Handle successful mobile unlock.
+ /// </summary>
+ private async Task HandleMobileUnlockSuccess(MobileLoginResult result)
+ {
+ _loadingIndicator.Show(Localizer["UnlockingVaultMessage"]);
+ _serverValidationErrors.Clear();
+
+ try
+ {
+ await StatusCheck();
+
+ // Revoke existing tokens
+ await AuthService.RemoveTokensAsync();
+
+ // Store the new tokens
+ await AuthService.StoreAccessTokenAsync(result.Token);
+ await AuthService.StoreRefreshTokenAsync(result.RefreshToken);
+
+ // Convert decryption key from base64 string to byte array
+ var decryptionKeyBytes = Convert.FromBase64String(result.DecryptionKey);
+
+ // Store the encryption key in memory
+ await AuthService.StoreEncryptionKeyAsync(decryptionKeyBytes);
+
+ await AuthStateProvider.GetAuthenticationStateAsync();
+
+ // Redirect to the page the user was trying to access before if set
+ var localStorageReturnUrl = await LocalStorage.GetItemAsync<string>(ReturnUrlKey);
+ if (!string.IsNullOrEmpty(localStorageReturnUrl))
+ {
+ await LocalStorage.RemoveItemAsync(ReturnUrlKey);
+ NavigationManager.NavigateTo(localStorageReturnUrl);
+ }
+ else
+ {
+ NavigationManager.NavigateTo("/");
+ }
+ }
+#if DEBUG
+ catch (Exception ex)
+ {
+ // If in debug mode show the actual exception.
+ _serverValidationErrors.AddError(ex.ToString());
+ }
+#else
+ catch
+ {
+ // If in release mode show a generic error.
+ _serverValidationErrors.AddError(Localizer["GenericUnlockError"]);
+ }
+#endif
+ finally
+ {
+ _loadingIndicator.Hide();
+ }
+ }
}
diff --git a/apps/server/AliasVault.Client/Resources/Pages/Auth/MobileLogin.en.resx b/apps/server/AliasVault.Client/Resources/Pages/Auth/MobileLogin.en.resx
index 856e84d6a..5ec771ddf 100644
--- a/apps/server/AliasVault.Client/Resources/Pages/Auth/MobileLogin.en.resx
+++ b/apps/server/AliasVault.Client/Resources/Pages/Auth/MobileLogin.en.resx
@@ -62,8 +62,16 @@
<value>Log in using Mobile App</value>
<comment>Page title for mobile unlock feature</comment>
</data>
+ <data name="UnlockTitle" xml:space="preserve">
+ <value>Unlock using Mobile App</value>
+ <comment>Modal title for mobile unlock feature</comment>
+ </data>
<data name="ScanQrCodeDescription" xml:space="preserve">
<value>Scan this QR code with your AliasVault mobile app to login.</value>
<comment>Description instructing user to scan QR code</comment>
</data>
+ <data name="ScanQrCodeToUnlock" xml:space="preserve">
+ <value>Scan this QR code with your AliasVault mobile app to unlock your vault.</value>
+ <comment>Description instructing user to scan QR code to unlock</comment>
+ </data>
</root>
diff --git a/apps/server/AliasVault.Client/Resources/Pages/Auth/MobileUnlockModal.en.resx b/apps/server/AliasVault.Client/Resources/Pages/Auth/MobileUnlockModal.en.resx
new file mode 100644
index 000000000..16166b115
--- /dev/null
+++ b/apps/server/AliasVault.Client/Resources/Pages/Auth/MobileUnlockModal.en.resx
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="PageTitle" xml:space="preserve">
+ <value>Log in using Mobile App</value>
+ <comment>Page title for mobile unlock feature</comment>
+ </data>
+ <data name="UnlockTitle" xml:space="preserve">
+ <value>Unlock using Mobile App</value>
+ <comment>Modal title for mobile unlock feature</comment>
+ </data>
+ <data name="ScanQrCodeDescription" xml:space="preserve">
+ <value>Scan this QR code with your AliasVault mobile app to login and unlock your vault.</value>
+ <comment>Description instructing user to scan QR code</comment>
+ </data>
+</root>
diff --git a/apps/server/AliasVault.Client/Resources/Pages/Auth/Unlock.en.resx b/apps/server/AliasVault.Client/Resources/Pages/Auth/Unlock.en.resx
index ee01f41a5..da067364b 100644
--- a/apps/server/AliasVault.Client/Resources/Pages/Auth/Unlock.en.resx
+++ b/apps/server/AliasVault.Client/Resources/Pages/Auth/Unlock.en.resx
@@ -122,4 +122,8 @@
<value>An error occurred while processing the login request. Try again (later).</value>
<comment>Generic error message for unlock failures</comment>
</data>
+ <data name="UnlockWithMobileButton" xml:space="preserve">
+ <value>Unlock with Mobile App</value>
+ <comment>Button text for unlocking with mobile app</comment>
+ </data>
</root>
\ No newline at end of file
diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
index e9c96b436..fadb8ed09 100644
--- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
+++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
@@ -1631,6 +1631,11 @@ video {
border-color: rgb(254 240 138 / var(--tw-border-opacity));
}
+.border-red-400 {
+ --tw-border-opacity: 1;
+ border-color: rgb(248 113 113 / var(--tw-border-opacity));
+}
+
.bg-amber-100 {
--tw-bg-opacity: 1;
background-color: rgb(254 243 199 / var(--tw-bg-opacity));
@@ -1830,6 +1835,11 @@ video {
background-color: rgb(234 179 8 / var(--tw-bg-opacity));
}
+.bg-black {
+ --tw-bg-opacity: 1;
+ background-color: rgb(0 0 0 / var(--tw-bg-opacity));
+}
+
.bg-opacity-50 {
--tw-bg-opacity: 0.5;
}
@@ -1838,6 +1848,10 @@ video {
--tw-bg-opacity: 0.75;
}
+.bg-opacity-80 {
+ --tw-bg-opacity: 0.8;
+}
+
.bg-gradient-to-r {
background-image: linear-gradient(to right, var(--tw-gradient-stops));
}
@@ -1967,6 +1981,11 @@ video {
padding-bottom: 1.5rem;
}
+.py-8 {
+ padding-top: 2rem;
+ padding-bottom: 2rem;
+}
+
.pb-28 {
padding-bottom: 7rem;
}
@@ -2027,6 +2046,10 @@ video {
padding-top: 2rem;
}
+.pt-5 {
+ padding-top: 1.25rem;
+}
+
.text-left {
text-align: left;
}
@@ -2377,11 +2400,20 @@ video {
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}
+.ring-inset {
+ --tw-ring-inset: inset;
+}
+
.ring-black {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(0 0 0 / var(--tw-ring-opacity));
}
+.ring-gray-300 {
+ --tw-ring-opacity: 1;
+ --tw-ring-color: rgb(209 213 219 / var(--tw-ring-opacity));
+}
+
.ring-opacity-5 {
--tw-ring-opacity: 0.05;
}
@@ -2890,6 +2922,11 @@ video {
border-color: rgb(133 77 14 / var(--tw-border-opacity));
}
+.dark\:border-red-700:is(.dark *) {
+ --tw-border-opacity: 1;
+ border-color: rgb(185 28 28 / var(--tw-border-opacity));
+}
+
.dark\:bg-amber-800\/30:is(.dark *) {
background-color: rgb(146 64 14 / 0.3);
}
@@ -3032,6 +3069,10 @@ video {
background-color: rgb(113 63 18 / 0.2);
}
+.dark\:bg-red-900\/30:is(.dark *) {
+ background-color: rgb(127 29 29 / 0.3);
+}
+
.dark\:bg-opacity-80:is(.dark *) {
--tw-bg-opacity: 0.8;
}
@@ -3191,6 +3232,11 @@ video {
color: rgb(156 163 175 / var(--tw-placeholder-opacity));
}
+.dark\:ring-gray-600:is(.dark *) {
+ --tw-ring-opacity: 1;
+ --tw-ring-color: rgb(75 85 99 / var(--tw-ring-opacity));
+}
+
.dark\:ring-offset-gray-800:is(.dark *) {
--tw-ring-offset-color: #1f2937;
}