Skip to content

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

Add explicit v2 models for auth endpoints (#2159)

Leendert de Borst8e39cc2eaa04
diff --git a/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs b/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs
index b6d1d8373..dcf812dda 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs
@@ -23,8 +23,7 @@ using AliasVault.Cryptography.Server;
using AliasVault.Shared.Core;
using AliasVault.Shared.Models.Enums;
using AliasVault.Shared.Models.WebApi;
-using AliasVault.Shared.Models.WebApi.V1.Auth;
-using AliasVault.Shared.Models.WebApi.V1.PasswordChange;
+using AliasVault.Shared.Models.WebApi.V2.Auth;
using AliasVault.Shared.Providers.Time;
using AliasVault.Shared.Server.Services;
using AliasVault.Shared.Server.Utilities;
@@ -36,7 +35,6 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.IdentityModel.Tokens;
using SecureRemotePassword;
-using V2Auth = AliasVault.Shared.Models.WebApi.V2.Auth;
/// <summary>
/// Auth controller for handling authentication.
@@ -390,7 +388,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
/// <param name="model">Register request model.</param>
/// <returns>IActionResult.</returns>
[HttpPost("register")]
- public async Task<IActionResult> Register([FromBody] V2Auth.RegisterRequest model)
+ public async Task<IActionResult> Register([FromBody] RegisterRequest model)
{
// Check if public registration is disabled in the configuration.
if (!config.PublicRegistrationEnabled)
@@ -580,7 +578,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
/// <returns>IActionResult.</returns>
[HttpPost("change-password")]
[Authorize]
- public async Task<IActionResult> ChangePassword([FromBody] V2Auth.PasswordChangeRequest model)
+ public async Task<IActionResult> ChangePassword([FromBody] PasswordChangeRequest model)
{
var user = await userManager.GetUserAsync(User);
if (user == null)
@@ -747,7 +745,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
/// <returns>IActionResult.</returns>
[HttpPost("mobile-login/initiate")]
[AllowAnonymous]
- public async Task<IActionResult> InitiateMobileLogin([FromBody] V2Auth.MobileLoginInitiateRequest model)
+ public async Task<IActionResult> InitiateMobileLogin([FromBody] MobileLoginInitiateRequest model)
{
// Reject invalid public key structure.
if (!MobileLoginPublicKeyValidator.IsValid(model.ClientPublicKey))
@@ -792,7 +790,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
context.MobileLoginRequests.Add(loginRequest);
await context.SaveChangesAsync();
- return Ok(new V2Auth.MobileLoginInitiateResponse
+ return Ok(new MobileLoginInitiateResponse
{
RequestId = requestId,
PollSecret = pollSecret,
@@ -806,7 +804,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
/// <returns>IActionResult.</returns>
[HttpPost("mobile-login/poll")]
[AllowAnonymous]
- public async Task<IActionResult> PollMobileLogin([FromBody] V2Auth.MobileLoginPollRequest model)
+ public async Task<IActionResult> PollMobileLogin([FromBody] MobileLoginPollRequest model)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
@@ -820,7 +818,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
if (loginRequest.DeclinedAt != null)
{
- return Ok(new V2Auth.MobileLoginPollResponse { Status = V2Auth.MobileLoginStatus.Declined });
+ return Ok(new MobileLoginPollResponse { Status = MobileLoginStatus.Declined });
}
if (loginRequest.FulfilledAt == null)
@@ -830,7 +828,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
return NotFound(ApiErrorCodeHelper.CreateErrorResponse(ApiErrorCode.MOBILE_LOGIN_REQUEST_NOT_FOUND, 404));
}
- return Ok(new V2Auth.MobileLoginPollResponse { Status = V2Auth.MobileLoginStatus.Pending });
+ return Ok(new MobileLoginPollResponse { Status = MobileLoginStatus.Pending });
}
// One-time use: an approved request is handed out once, and only shortly after the approval.
@@ -876,7 +874,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
// The client needs the key derivation parameters next to the unlock key to be able to unlock offline later.
var tokenModel = await GenerateNewTokensForUser(user, extendedLifetime: true);
var encryptionSettings = await AuthHelper.GetUserLatestVaultEncryptionSettingsAsync(context, user);
- var payload = new V2Auth.MobileLoginPayload
+ var payload = new MobileLoginPayload
{
Username = user.UserName!,
Token = tokenModel.Token,
@@ -893,9 +891,9 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
await authLoggingService.LogAuthEventSuccessAsync(user.UserName!, AuthEventType.MobileLogin);
- return Ok(new V2Auth.MobileLoginPollResponse
+ return Ok(new MobileLoginPollResponse
{
- Status = V2Auth.MobileLoginStatus.Approved,
+ Status = MobileLoginStatus.Approved,
EncryptedSymmetricKey = encryptedSymmetricKey,
EncryptedPayload = encryptedPayload,
EncryptedUnlockKey = encryptedUnlockKey,
@@ -909,7 +907,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
/// <returns>IActionResult.</returns>
[HttpPost("mobile-login/details")]
[Authorize]
- public async Task<IActionResult> GetMobileLoginDetails([FromBody] V2Auth.MobileLoginRequestReference model)
+ public async Task<IActionResult> GetMobileLoginDetails([FromBody] MobileLoginRequestReference model)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
@@ -919,7 +917,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
return NotFound(ApiErrorCodeHelper.CreateErrorResponse(ApiErrorCode.MOBILE_LOGIN_REQUEST_NOT_FOUND, 404));
}
- return Ok(new V2Auth.MobileLoginDetailsResponse
+ return Ok(new MobileLoginDetailsResponse
{
ClientPublicKey = loginRequest.ClientPublicKey,
IpAddress = loginRequest.ClientIpAddress,
@@ -938,7 +936,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
/// <returns>IActionResult.</returns>
[HttpPost("mobile-login/submit")]
[Authorize]
- public async Task<IActionResult> SubmitMobileLogin([FromBody] V2Auth.MobileLoginSubmitRequest model)
+ public async Task<IActionResult> SubmitMobileLogin([FromBody] MobileLoginSubmitRequest model)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
@@ -982,7 +980,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
/// <returns>IActionResult.</returns>
[HttpPost("mobile-login/decline")]
[Authorize]
- public async Task<IActionResult> DeclineMobileLogin([FromBody] V2Auth.MobileLoginRequestReference model)
+ public async Task<IActionResult> DeclineMobileLogin([FromBody] MobileLoginRequestReference model)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
diff --git a/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs b/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs
index 4e11aa3fc..defea9255 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs
@@ -15,7 +15,7 @@ using AliasVault.Auth;
using AliasVault.Cryptography.Client;
using AliasVault.Shared.Models.Enums;
using AliasVault.Shared.Models.WebApi;
-using AliasVault.Shared.Models.WebApi.V1.Auth;
+using AliasVault.Shared.Models.WebApi.V2.Auth;
using AliasVault.Shared.Models.WebApi.V2.Groups;
using AliasVault.Shared.Providers.Time;
using AliasVault.Shared.Server.Capabilities;
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/DeleteAccountRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/DeleteAccountRequest.cs
new file mode 100644
index 000000000..56381a74d
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/DeleteAccountRequest.cs
@@ -0,0 +1,42 @@
+//-----------------------------------------------------------------------
+// <copyright file="DeleteAccountRequest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+
+/// <summary>
+/// Request model for deleting an account, carrying the SRP proof of the current password.
+/// </summary>
+public class DeleteAccountRequest
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="DeleteAccountRequest"/> class.
+ /// </summary>
+ /// <param name="username">The username of the account to delete.</param>
+ /// <param name="clientPublicEphemeral">The client public ephemeral of the account to delete.</param>
+ /// <param name="clientSessionProof">The client session proof of the account to delete.</param>
+ public DeleteAccountRequest(string username, string clientPublicEphemeral, string clientSessionProof)
+ {
+ Username = username;
+ ClientPublicEphemeral = clientPublicEphemeral;
+ ClientSessionProof = clientSessionProof;
+ }
+
+ /// <summary>
+ /// Gets or sets the username of the account to delete.
+ /// </summary>
+ public string Username { get; set; }
+
+ /// <summary>
+ /// Gets or sets the client public ephemeral of the account to delete.
+ /// </summary>
+ public string ClientPublicEphemeral { get; set; }
+
+ /// <summary>
+ /// Gets or sets the client session proof of the account to delete.
+ /// </summary>
+ public string ClientSessionProof { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/LoginInitiateRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/LoginInitiateRequest.cs
new file mode 100644
index 000000000..1a403f384
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/LoginInitiateRequest.cs
@@ -0,0 +1,28 @@
+//-----------------------------------------------------------------------
+// <copyright file="LoginInitiateRequest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+
+/// <summary>
+/// Request that starts an SRP handshake for a username.
+/// </summary>
+public class LoginInitiateRequest
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="LoginInitiateRequest"/> class.
+ /// </summary>
+ /// <param name="username">Username.</param>
+ public LoginInitiateRequest(string username)
+ {
+ Username = username.ToLowerInvariant().Trim();
+ }
+
+ /// <summary>
+ /// Gets the username.
+ /// </summary>
+ public string Username { get; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/LoginInitiateResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/LoginInitiateResponse.cs
new file mode 100644
index 000000000..0150d8d15
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/LoginInitiateResponse.cs
@@ -0,0 +1,65 @@
+//-----------------------------------------------------------------------
+// <copyright file="LoginInitiateResponse.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+
+using System.Text.Json.Serialization;
+
+/// <summary>
+/// Server answer to an SRP handshake: the stored salt, the server ephemeral and the key derivation parameters.
+/// </summary>
+public class LoginInitiateResponse
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="LoginInitiateResponse"/> class.
+ /// </summary>
+ /// <param name="salt">Salt.</param>
+ /// <param name="serverEphemeral">Server ephemeral.</param>
+ /// <param name="encryptionType">Encryption type.</param>
+ /// <param name="encryptionSettings">Encryption settings.</param>
+ /// <param name="srpIdentity">The SRP identity.</param>
+ public LoginInitiateResponse(string salt, string serverEphemeral, string encryptionType, string encryptionSettings, string srpIdentity)
+ {
+ Salt = salt;
+ ServerEphemeral = serverEphemeral;
+ EncryptionType = encryptionType;
+ EncryptionSettings = encryptionSettings;
+ SrpIdentity = srpIdentity;
+ }
+
+ /// <summary>
+ /// Gets or sets the salt.
+ /// </summary>
+ [JsonPropertyName("salt")]
+ public string Salt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the server's public ephemeral value.
+ /// </summary>
+ [JsonPropertyName("serverEphemeral")]
+ public string ServerEphemeral { get; set; }
+
+ /// <summary>
+ /// Gets or sets the encryption type.
+ /// </summary>
+ [JsonPropertyName("encryptionType")]
+ public string EncryptionType { get; set; }
+
+ /// <summary>
+ /// Gets or sets the encryption settings.
+ /// </summary>
+ [JsonPropertyName("encryptionSettings")]
+ public string EncryptionSettings { get; set; }
+
+ /// <summary>
+ /// Gets or sets the SRP identity to use for authentication. This is a fixed value that doesn't change
+ /// even if the display username is updated. Clients should use this value (instead of the typed username)
+ /// for all SRP operations.
+ /// </summary>
+ [JsonPropertyName("srpIdentity")]
+ public string SrpIdentity { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/PasswordChangeInitiateResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/PasswordChangeInitiateResponse.cs
new file mode 100644
index 000000000..2e9133ce3
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/PasswordChangeInitiateResponse.cs
@@ -0,0 +1,64 @@
+//-----------------------------------------------------------------------
+// <copyright file="PasswordChangeInitiateResponse.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+
+using System.Text.Json.Serialization;
+
+/// <summary>
+/// Server answer to GET /v2/Auth/change-password/initiate: the SRP handshake material for the current password.
+/// </summary>
+public class PasswordChangeInitiateResponse
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PasswordChangeInitiateResponse"/> class.
+ /// </summary>
+ /// <param name="salt">Salt.</param>
+ /// <param name="serverEphemeral">Server ephemeral.</param>
+ /// <param name="encryptionType">Encryption type.</param>
+ /// <param name="encryptionSettings">Encryption settings.</param>
+ /// <param name="srpIdentity">The SRP identity.</param>
+ public PasswordChangeInitiateResponse(string salt, string serverEphemeral, string encryptionType, string encryptionSettings, string srpIdentity)
+ {
+ Salt = salt;
+ ServerEphemeral = serverEphemeral;
+ EncryptionType = encryptionType;
+ EncryptionSettings = encryptionSettings;
+ SrpIdentity = srpIdentity;
+ }
+
+ /// <summary>
+ /// Gets or sets the salt.
+ /// </summary>
+ [JsonPropertyName("salt")]
+ public string Salt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the server's public ephemeral value.
+ /// </summary>
+ [JsonPropertyName("serverEphemeral")]
+ public string ServerEphemeral { get; set; }
+
+ /// <summary>
+ /// Gets or sets the encryption type.
+ /// </summary>
+ [JsonPropertyName("encryptionType")]
+ public string EncryptionType { get; set; }
+
+ /// <summary>
+ /// Gets or sets the encryption settings.
+ /// </summary>
+ [JsonPropertyName("encryptionSettings")]
+ public string EncryptionSettings { get; set; }
+
+ /// <summary>
+ /// Gets or sets the SRP identity to use for authentication. This is a fixed value that doesn't change
+ /// even if the display username is updated. Clients should use this value for all SRP operations.
+ /// </summary>
+ [JsonPropertyName("srpIdentity")]
+ public string SrpIdentity { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/TokenModel.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/TokenModel.cs
new file mode 100644
index 000000000..a9a862861
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/TokenModel.cs
@@ -0,0 +1,28 @@
+//-----------------------------------------------------------------------
+// <copyright file="TokenModel.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+
+using System.Text.Json.Serialization;
+
+/// <summary>
+/// Access token and refresh token pair handed out by the v2 auth endpoints.
+/// </summary>
+public class TokenModel
+{
+ /// <summary>
+ /// Gets or sets the access token.
+ /// </summary>
+ [JsonPropertyName("token")]
+ public string Token { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the refresh token.
+ /// </summary>
+ [JsonPropertyName("refreshToken")]
+ public string RefreshToken { get; set; } = null!;
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginRequest.cs
new file mode 100644
index 000000000..434895018
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginRequest.cs
@@ -0,0 +1,49 @@
+//-----------------------------------------------------------------------
+// <copyright file="ValidateLoginRequest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+
+/// <summary>
+/// Request that finishes an SRP handshake with the client's proof.
+/// </summary>
+public class ValidateLoginRequest
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ValidateLoginRequest"/> class.
+ /// </summary>
+ /// <param name="username">Username.</param>
+ /// <param name="rememberMe">Indicates if the user wants to be remembered which extends the refresh token lifetime.</param>
+ /// <param name="clientPublicEphemeral">Client public ephemeral.</param>
+ /// <param name="clientSessionProof">Client session proof.</param>
+ public ValidateLoginRequest(string username, bool rememberMe, string clientPublicEphemeral, string clientSessionProof)
+ {
+ Username = username.ToLowerInvariant().Trim();
+ RememberMe = rememberMe;
+ ClientPublicEphemeral = clientPublicEphemeral;
+ ClientSessionProof = clientSessionProof;
+ }
+
+ /// <summary>
+ /// Gets the username.
+ /// </summary>
+ public string Username { get; }
+
+ /// <summary>
+ /// Gets a value indicating whether the user wants to be remembered which extends the refresh token lifetime.
+ /// </summary>
+ public bool RememberMe { get; }
+
+ /// <summary>
+ /// Gets the client's public ephemeral value.
+ /// </summary>
+ public string ClientPublicEphemeral { get; }
+
+ /// <summary>
+ /// Gets the client's session proof.
+ /// </summary>
+ public string ClientSessionProof { get; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginRequest2Fa.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginRequest2Fa.cs
new file mode 100644
index 000000000..241531a8e
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginRequest2Fa.cs
@@ -0,0 +1,33 @@
+//-----------------------------------------------------------------------
+// <copyright file="ValidateLoginRequest2Fa.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+
+/// <summary>
+/// Request that finishes an SRP handshake together with a two-factor authentication code.
+/// </summary>
+public class ValidateLoginRequest2Fa : ValidateLoginRequest
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ValidateLoginRequest2Fa"/> class.
+ /// </summary>
+ /// <param name="username">Username.</param>
+ /// <param name="rememberMe">Indicates if the user wants to be remembered which extends the refresh token lifetime.</param>
+ /// <param name="clientPublicEphemeral">Client public ephemeral.</param>
+ /// <param name="clientSessionProof">Client session proof.</param>
+ /// <param name="code2Fa">2-factor authentication code.</param>
+ public ValidateLoginRequest2Fa(string username, bool rememberMe, string clientPublicEphemeral, string clientSessionProof, int code2Fa)
+ : base(username, rememberMe, clientPublicEphemeral, clientSessionProof)
+ {
+ Code2Fa = code2Fa;
+ }
+
+ /// <summary>
+ /// Gets the 2-factor authentication code.
+ /// </summary>
+ public int Code2Fa { get; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginRequestRecoveryCode.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginRequestRecoveryCode.cs
new file mode 100644
index 000000000..ef4555b5f
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginRequestRecoveryCode.cs
@@ -0,0 +1,33 @@
+//-----------------------------------------------------------------------
+// <copyright file="ValidateLoginRequestRecoveryCode.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+
+/// <summary>
+/// Request that finishes an SRP handshake together with a two-factor recovery code.
+/// </summary>
+public class ValidateLoginRequestRecoveryCode : ValidateLoginRequest
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ValidateLoginRequestRecoveryCode"/> class.
+ /// </summary>
+ /// <param name="username">Username.</param>
+ /// <param name="rememberMe">Indicates if the user wants to be remembered which extends the refresh token lifetime.</param>
+ /// <param name="clientPublicEphemeral">Client public ephemeral.</param>
+ /// <param name="clientSessionProof">Client session proof.</param>
+ /// <param name="recoveryCode">2-factor recovery code.</param>
+ public ValidateLoginRequestRecoveryCode(string username, bool rememberMe, string clientPublicEphemeral, string clientSessionProof, string recoveryCode)
+ : base(username, rememberMe, clientPublicEphemeral, clientSessionProof)
+ {
+ RecoveryCode = recoveryCode;
+ }
+
+ /// <summary>
+ /// Gets the 2-factor authentication recovery code.
+ /// </summary>
+ public string RecoveryCode { get; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginResponse.cs
new file mode 100644
index 000000000..1f14026d5
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateLoginResponse.cs
@@ -0,0 +1,47 @@
+//-----------------------------------------------------------------------
+// <copyright file="ValidateLoginResponse.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+
+using System.Text.Json.Serialization;
+
+/// <summary>
+/// Server answer to a finished SRP handshake: the server proof plus the tokens, unless two-factor is still pending.
+/// </summary>
+public class ValidateLoginResponse
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ValidateLoginResponse"/> class.
+ /// </summary>
+ /// <param name="requiresTwoFactor">Whether two factor authentication is required to login the user.</param>
+ /// <param name="serverSessionProof">Client session proof.</param>
+ /// <param name="token">Token model.</param>
+ public ValidateLoginResponse(bool requiresTwoFactor, string serverSessionProof, TokenModel? token)
+ {
+ RequiresTwoFactor = requiresTwoFactor;
+ ServerSessionProof = serverSessionProof;
+ Token = token;
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether two factor authentication is required to finish login.
+ /// </summary>
+ [JsonPropertyName("requiresTwoFactor")]
+ public bool RequiresTwoFactor { get; set; }
+
+ /// <summary>
+ /// Gets or sets the server's session proof.
+ /// </summary>
+ [JsonPropertyName("serverSessionProof")]
+ public string ServerSessionProof { get; set; }
+
+ /// <summary>
+ /// Gets or sets the JWT and refresh token.
+ /// </summary>
+ [JsonPropertyName("token")]
+ public TokenModel? Token { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateUsernameRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateUsernameRequest.cs
new file mode 100644
index 000000000..0efa6eecd
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/ValidateUsernameRequest.cs
@@ -0,0 +1,19 @@
+//-----------------------------------------------------------------------
+// <copyright file="ValidateUsernameRequest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+
+/// <summary>
+/// A request to validate a username.
+/// </summary>
+public class ValidateUsernameRequest
+{
+ /// <summary>
+ /// Gets the username to validate.
+ /// </summary>
+ public required string Username { get; init; } = string.Empty;
+}