mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-03-20 23:52:31 -04:00
Expose all config settings through config object (#317)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
@inherits AliasVault.Client.Auth.Pages.Base.LoginBase
|
||||
@layout Auth.Layout.EmptyLayout
|
||||
@attribute [AllowAnonymous]
|
||||
@inject IConfiguration Configuration
|
||||
@using System.Text.Json
|
||||
@using AliasVault.Client.Utilities
|
||||
@using AliasVault.Cryptography.Client
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace AliasVault.Client;
|
||||
|
||||
/// <summary>
|
||||
@@ -13,20 +12,19 @@ namespace AliasVault.Client;
|
||||
public class Config
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the admin password hash which is generated by install.sh and will be set
|
||||
/// as the default password for the admin user.
|
||||
/// Gets or sets the API URL for the AliasVault server.
|
||||
/// </summary>
|
||||
public string ApiUrl { get; set; } = "false";
|
||||
public string ApiUrl { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the domains that the AliasVault server is listening for.
|
||||
/// Gets or sets the list of private email domains that the AliasVault server is listening for.
|
||||
/// Email addresses that client vault users use will be registered at the server
|
||||
/// to get exclusive access to the email address.
|
||||
/// </summary>
|
||||
public List<string> PrivateEmailDomains { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the public email domains that are allowed to be used by the client vault users.
|
||||
/// Gets or sets the list of public email domains that are allowed to be used by the client vault users.
|
||||
/// </summary>
|
||||
public List<string> PublicEmailDomains { get; set; } =
|
||||
[
|
||||
@@ -41,4 +39,22 @@ public class Config
|
||||
"spamok.es",
|
||||
"spamok.fr",
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to use a debug encryption key.
|
||||
/// This should only be set to true in development environments.
|
||||
/// </summary>
|
||||
public bool UseDebugEncryptionKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of cryptography to use for password hashing.
|
||||
/// Currently supports "Argon2Id".
|
||||
/// </summary>
|
||||
public string? CryptographyOverrideType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the JSON string containing cryptography settings.
|
||||
/// For Argon2Id, this includes DegreeOfParallelism, MemorySize, and Iterations.
|
||||
/// </summary>
|
||||
public string? CryptographyOverrideSettings { get; set; }
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
/// <param name="httpClient">The HTTP client.</param>
|
||||
/// <param name="localStorage">The local storage service.</param>
|
||||
/// <param name="environment">IWebAssemblyHostEnvironment instance.</param>
|
||||
/// <param name="configuration">IConfiguration instance.</param>
|
||||
/// <param name="config">Config instance.</param>
|
||||
/// <param name="jsInteropService">JSInteropService instance.</param>
|
||||
public sealed class AuthService(HttpClient httpClient, ILocalStorageService localStorage, IWebAssemblyHostEnvironment environment, IConfiguration configuration, JsInteropService jsInteropService)
|
||||
public sealed class AuthService(HttpClient httpClient, ILocalStorageService localStorage, IWebAssemblyHostEnvironment environment, Config config, JsInteropService jsInteropService)
|
||||
{
|
||||
private const string AccessTokenKey = "token";
|
||||
private const string RefreshTokenKey = "refreshToken";
|
||||
@@ -107,7 +107,7 @@ public sealed class AuthService(HttpClient httpClient, ILocalStorageService loca
|
||||
/// <returns>SrpArgonEncryption key as base64 string.</returns>
|
||||
public string GetEncryptionKeyAsBase64Async()
|
||||
{
|
||||
if (environment.IsDevelopment() && configuration["UseDebugEncryptionKey"] == "true")
|
||||
if (environment.IsDevelopment() && config.UseDebugEncryptionKey)
|
||||
{
|
||||
// When project runs in development mode a static encryption key will be used.
|
||||
// This allows to skip the unlock screen for faster development.
|
||||
|
||||
@@ -16,34 +16,14 @@ using Microsoft.AspNetCore.Components.Authorization;
|
||||
using SecureRemotePassword;
|
||||
|
||||
/// <summary>
|
||||
/// This service is responsible for registering a new user.
|
||||
/// Service responsible for handling user registration operations.
|
||||
/// </summary>
|
||||
public class UserRegistrationService
|
||||
/// <param name="httpClient">The HTTP client used for making registration requests.</param>
|
||||
/// <param name="authStateProvider">The provider that manages authentication state.</param>
|
||||
/// <param name="authService">The service handling authentication operations.</param>
|
||||
/// <param name="config">The application configuration.</param>
|
||||
public class UserRegistrationService(HttpClient httpClient, AuthenticationStateProvider authStateProvider, AuthService authService, Config config)
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly AuthenticationStateProvider _authStateProvider;
|
||||
private readonly AuthService _authService;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserRegistrationService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="httpClient">The HTTP client.</param>
|
||||
/// <param name="authStateProvider">The authentication state provider.</param>
|
||||
/// <param name="authService">The authentication service.</param>
|
||||
/// <param name="configuration">The configuration.</param>
|
||||
public UserRegistrationService(
|
||||
HttpClient httpClient,
|
||||
AuthenticationStateProvider authStateProvider,
|
||||
AuthService authService,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_authStateProvider = authStateProvider;
|
||||
_authService = authService;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new user asynchronously.
|
||||
/// </summary>
|
||||
@@ -59,10 +39,10 @@ public class UserRegistrationService
|
||||
|
||||
string encryptionType = Defaults.EncryptionType;
|
||||
string encryptionSettings = Defaults.EncryptionSettings;
|
||||
if (_configuration["CryptographyOverrideType"] is not null && _configuration["CryptographyOverrideSettings"] is not null)
|
||||
if (config.CryptographyOverrideType is not null && config.CryptographyOverrideSettings is not null)
|
||||
{
|
||||
encryptionType = _configuration["CryptographyOverrideType"]!;
|
||||
encryptionSettings = _configuration["CryptographyOverrideSettings"]!;
|
||||
encryptionType = config.CryptographyOverrideType;
|
||||
encryptionSettings = config.CryptographyOverrideSettings;
|
||||
}
|
||||
|
||||
var passwordHash = await Encryption.DeriveKeyFromPasswordAsync(password, salt, encryptionType, encryptionSettings);
|
||||
@@ -70,7 +50,7 @@ public class UserRegistrationService
|
||||
var srpSignup = Srp.PasswordChangeAsync(client, salt, username, passwordHashString);
|
||||
|
||||
var registerRequest = new RegisterRequest(srpSignup.Username, srpSignup.Salt, srpSignup.Verifier, encryptionType, encryptionSettings);
|
||||
var result = await _httpClient.PostAsJsonAsync("api/v1/Auth/register", registerRequest);
|
||||
var result = await httpClient.PostAsJsonAsync("api/v1/Auth/register", registerRequest);
|
||||
var responseContent = await result.Content.ReadAsStringAsync();
|
||||
|
||||
if (!result.IsSuccessStatusCode)
|
||||
@@ -86,10 +66,10 @@ public class UserRegistrationService
|
||||
return (false, "An error occurred during registration.");
|
||||
}
|
||||
|
||||
await _authService.StoreEncryptionKeyAsync(passwordHash);
|
||||
await _authService.StoreAccessTokenAsync(tokenObject.Token);
|
||||
await _authService.StoreRefreshTokenAsync(tokenObject.RefreshToken);
|
||||
await _authStateProvider.GetAuthenticationStateAsync();
|
||||
await authService.StoreEncryptionKeyAsync(passwordHash);
|
||||
await authService.StoreAccessTokenAsync(tokenObject.Token);
|
||||
await authService.StoreRefreshTokenAsync(tokenObject.RefreshToken);
|
||||
await authStateProvider.GetAuthenticationStateAsync();
|
||||
|
||||
return (true, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user