Skip to content

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

Code style refactor (#11)

Leendert de Borstd456932c929d
diff --git a/.editorconfig b/.editorconfig
index 0968faee9..e756cdac4 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -120,3 +120,5 @@ dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
end_of_line = crlf
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_null_propagation = true:suggestion
diff --git a/SonarLint.xml b/SonarLint.xml
new file mode 100644
index 000000000..f03773dad
--- /dev/null
+++ b/SonarLint.xml
@@ -0,0 +1,13 @@
+<SonarLint>
+ <Rules>
+ <Rule>
+ <Key>S1135</Key>
+ <Parameters>
+ <Parameter>
+ <Name>sonarlint.rule.enabled</Name>
+ <Value>false</Value>
+ </Parameter>
+ </Parameters>
+ </Rule>
+ </Rules>
+</SonarLint>
diff --git a/src/AliasDb/Identity.cs b/src/AliasDb/Identity.cs
index 1d3d0dd3d..c505ddeca 100644
--- a/src/AliasDb/Identity.cs
+++ b/src/AliasDb/Identity.cs
@@ -32,14 +32,14 @@ public class Identity
/// </summary>
[StringLength(255)]
[Column(TypeName = "VARCHAR")]
- public string FirstName { get; set; } = null!;
+ public string? FirstName { get; set; } = null!;
/// <summary>
/// Gets or sets the last name.
/// </summary>
[StringLength(255)]
[Column(TypeName = "VARCHAR")]
- public string LastName { get; set; } = null!;
+ public string? LastName { get; set; } = null!;
/// <summary>
/// Gets or sets the nickname.
diff --git a/src/AliasVault.Api/Controllers/AliasController.cs b/src/AliasVault.Api/Controllers/AliasController.cs
index 192f26380..1cc4f5bfb 100644
--- a/src/AliasVault.Api/Controllers/AliasController.cs
+++ b/src/AliasVault.Api/Controllers/AliasController.cs
@@ -7,6 +7,7 @@
namespace AliasVault.Api.Controllers;
+using System.Globalization;
using AliasDb;
using AliasVault.Shared.Models.WebApi;
using Microsoft.AspNetCore.Identity;
@@ -15,15 +16,19 @@ using Microsoft.EntityFrameworkCore;
using Identity = AliasVault.Shared.Models.WebApi.Identity;
using Service = AliasVault.Shared.Models.WebApi.Service;
-public class AliasController : AuthenticatedRequestController
+/// <summary>
+/// Alias controller for handling CRUD operations on the database for alias entities.
+/// </summary>
+/// <param name="context">DbContext instance.</param>
+/// <param name="userManager">UserManager instance.</param>
+public class AliasController(AliasDbContext context, UserManager<IdentityUser> userManager) : AuthenticatedRequestController(userManager)
{
- private readonly AliasDbContext _context;
-
- public AliasController(AliasDbContext context, UserManager<IdentityUser> userManager) : base(userManager)
- {
- _context = context;
- }
+ private readonly AliasDbContext _context = context;
+ /// <summary>
+ /// Get all alias items for the current user.
+ /// </summary>
+ /// <returns>List of aliases in JSON format.</returns>
[HttpGet("items")]
public async Task<IActionResult> GetItems()
{
@@ -42,8 +47,8 @@ public class AliasController : AuthenticatedRequestController
{
Id = x.Id,
Logo = x.Service.Logo,
- Service = x.Service.Name,
- CreateDate = x.CreatedAt
+ Service = x.Service.Name ?? "n/a",
+ CreateDate = x.CreatedAt,
})
.ToListAsync();
@@ -51,6 +56,11 @@ public class AliasController : AuthenticatedRequestController
return Ok(aliases);
}
+ /// <summary>
+ /// Get a single alias item by its ID.
+ /// </summary>
+ /// <param name="aliasId">ID of the alias.</param>
+ /// <returns>Alias object as JSON.</returns>
[HttpGet("{aliasId}")]
public async Task<IActionResult> GetAlias(Guid aliasId)
{
@@ -70,11 +80,11 @@ public class AliasController : AuthenticatedRequestController
{
Service = new Service()
{
- Name = x.Service.Name,
+ Name = x.Service.Name ?? "n/a",
Url = x.Service.Url,
- LogoUrl = "",
+ LogoUrl = string.Empty,
CreatedAt = x.Service.CreatedAt,
- UpdatedAt = x.Service.UpdatedAt
+ UpdatedAt = x.Service.UpdatedAt,
},
Identity = new Identity()
{
@@ -93,18 +103,17 @@ public class AliasController : AuthenticatedRequestController
PhoneMobile = x.Identity.PhoneMobile,
BankAccountIBAN = x.Identity.BankAccountIBAN,
CreatedAt = x.Identity.CreatedAt,
- UpdatedAt = x.Identity.UpdatedAt
+ UpdatedAt = x.Identity.UpdatedAt,
},
Password = new AliasVault.Shared.Models.WebApi.Password()
{
- Value = x.Passwords.First().Value ?? "",
- Description = "",
+ Value = x.Passwords.First().Value ?? string.Empty,
+ Description = string.Empty,
CreatedAt = x.Passwords.First().CreatedAt,
- UpdatedAt = x.Passwords.First().UpdatedAt
+ UpdatedAt = x.Passwords.First().UpdatedAt,
},
CreateDate = x.CreatedAt,
- LastUpdate = x.UpdatedAt
-
+ LastUpdate = x.UpdatedAt,
})
.FirstAsync();
@@ -112,10 +121,10 @@ public class AliasController : AuthenticatedRequestController
}
/// <summary>
- /// Insert a new entry to the database.
+ /// Insert a new alias to the database.
/// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
+ /// <param name="model">Alias model.</param>
+ /// <returns>ID of newly inserted alias.</returns>
[HttpPut("")]
public async Task<IActionResult> Insert([FromBody] Alias model)
{
@@ -125,35 +134,37 @@ public class AliasController : AuthenticatedRequestController
return Unauthorized();
}
- var login = new Login();
- login.UserId = user.Id;
- login.CreatedAt = DateTime.UtcNow;
- login.UpdatedAt = DateTime.UtcNow;
- login.Identity = new AliasDb.Identity()
+ var login = new Login
{
- NickName = model.Identity.NickName,
- FirstName = model.Identity.FirstName,
- LastName = model.Identity.LastName,
- BirthDate = DateTime.Parse(model.Identity.BirthDate),
- Gender = model.Identity.Gender,
- AddressStreet = model.Identity.AddressStreet,
- AddressCity = model.Identity.AddressCity,
- AddressState = model.Identity.AddressState,
- AddressZipCode = model.Identity.AddressZipCode,
- AddressCountry = model.Identity.AddressCountry,
- Hobbies = model.Identity.Hobbies,
- EmailPrefix = model.Identity.EmailPrefix,
- PhoneMobile = model.Identity.PhoneMobile,
- BankAccountIBAN = model.Identity.BankAccountIBAN,
+ UserId = user.Id,
CreatedAt = DateTime.UtcNow,
- UpdatedAt = DateTime.UtcNow
+ UpdatedAt = DateTime.UtcNow,
+ Identity = new AliasDb.Identity()
+ {
+ NickName = model.Identity.NickName,
+ FirstName = model.Identity.FirstName,
+ LastName = model.Identity.LastName,
+ BirthDate = DateTime.Parse(model.Identity.BirthDate ?? "1900-01-01", new CultureInfo("en-US")),
+ Gender = model.Identity.Gender,
+ AddressStreet = model.Identity.AddressStreet,
+ AddressCity = model.Identity.AddressCity,
+ AddressState = model.Identity.AddressState,
+ AddressZipCode = model.Identity.AddressZipCode,
+ AddressCountry = model.Identity.AddressCountry,
+ Hobbies = model.Identity.Hobbies,
+ EmailPrefix = model.Identity.EmailPrefix,
+ PhoneMobile = model.Identity.PhoneMobile,
+ BankAccountIBAN = model.Identity.BankAccountIBAN,
+ CreatedAt = DateTime.UtcNow,
+ UpdatedAt = DateTime.UtcNow,
+ },
};
login.Passwords.Add(new AliasDb.Password()
{
Value = model.Password.Value,
CreatedAt = DateTime.UtcNow,
- UpdatedAt = DateTime.UtcNow
+ UpdatedAt = DateTime.UtcNow,
});
login.Service = new AliasDb.Service()
@@ -161,23 +172,23 @@ public class AliasController : AuthenticatedRequestController
Name = model.Service.Name,
Url = model.Service.Url,
CreatedAt = DateTime.UtcNow,
- UpdatedAt = DateTime.UtcNow
+ UpdatedAt = DateTime.UtcNow,
};
- _context.Logins.Add(login);
+ await _context.Logins.AddAsync(login);
await _context.SaveChangesAsync();
return Ok(login.Id);
}
/// <summary>
- /// Update an existing entry in the database.
+ /// Update an existing alias entry in the database.
/// </summary>
- /// <param name="model"></param>
- /// <param name="aliasId"></param>
- /// <returns></returns>
+ /// <param name="aliasId">The alias ID to update.</param>
+ /// <param name="model">Alias model.</param>
+ /// <returns>ID of updated alias entry.</returns>
[HttpPost("{aliasId}")]
- public async Task<IActionResult> Update([FromBody] Alias model, Guid aliasId)
+ public async Task<IActionResult> Update(Guid aliasId, [FromBody] Alias model)
{
var user = await GetCurrentUserAsync();
if (user == null)
@@ -198,7 +209,7 @@ public class AliasController : AuthenticatedRequestController
login.Identity.NickName = model.Identity.NickName;
login.Identity.FirstName = model.Identity.FirstName;
login.Identity.LastName = model.Identity.LastName;
- login.Identity.BirthDate = DateTime.Parse(model.Identity.BirthDate);
+ login.Identity.BirthDate = DateTime.Parse(model.Identity.BirthDate ?? "1900-01-01", new CultureInfo("en-US"));
login.Identity.Gender = model.Identity.Gender;
login.Identity.AddressStreet = model.Identity.AddressStreet;
login.Identity.AddressCity = model.Identity.AddressCity;
@@ -223,9 +234,10 @@ public class AliasController : AuthenticatedRequestController
}
/// <summary>
- /// Delete an existing entry from the database.
+ /// Delete an existing alias entry from the database.
/// </summary>
- /// <param name="aliasId"></param>
+ /// <param name="aliasId">ID of the alias to delete.</param>
+ /// <returns>HTTP status code.</returns>
[HttpDelete("{aliasId}")]
public async Task<IActionResult> Delete(Guid aliasId)
{
diff --git a/src/AliasVault.Api/Controllers/AuthController.cs b/src/AliasVault.Api/Controllers/AuthController.cs
index 0aee97213..d3941e86a 100644
--- a/src/AliasVault.Api/Controllers/AuthController.cs
+++ b/src/AliasVault.Api/Controllers/AuthController.cs
@@ -20,30 +20,14 @@ using Microsoft.IdentityModel.Tokens;
/// <summary>
/// Auth controller for handling authentication.
/// </summary>
+/// <param name="context">AliasDbContext instance.</param>
+/// <param name="userManager">UserManager instance.</param>
+/// <param name="signInManager">SignInManager instance.</param>
+/// <param name="configuration">IConfiguration instance.</param>
[Route("api/[controller]")]
[ApiController]
-public class AuthController : ControllerBase
+public class AuthController(AliasDbContext context, UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager, IConfiguration configuration) : ControllerBase
{
- private readonly AliasDbContext _context;
- private readonly UserManager<IdentityUser> _userManager;
- private readonly SignInManager<IdentityUser> _signInManager;
- private readonly IConfiguration _configuration;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AuthController"/> class.
- /// </summary>
- /// <param name="context">AliasDbContext instance.</param>
- /// <param name="userManager">UserManager instance.</param>
- /// <param name="signInManager">SignInManager instance.</param>
- /// <param name="configuration">IConfiguration instance.</param>
- public AuthController(AliasDbContext context, UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager, IConfiguration configuration)
- {
- _context = context;
- _userManager = userManager;
- _signInManager = signInManager;
- _configuration = configuration;
- }
-
/// <summary>
/// Login endpoint used to process login attempt using credentials.
/// </summary>
@@ -52,8 +36,8 @@ public class AuthController : ControllerBase
[HttpPost("login")]
public async Task<IActionResult> Login([FromBody] LoginModel model)
{
- var user = await _userManager.FindByEmailAsync(model.Email);
- if (user != null && await _userManager.CheckPasswordAsync(user, model.Password))
+ var user = await userManager.FindByEmailAsync(model.Email);
+ if (user != null && await userManager.CheckPasswordAsync(user, model.Password))
{
var tokenModel = await GenerateNewTokenForUser(user);
return Ok(tokenModel);
@@ -76,7 +60,7 @@ public class AuthController : ControllerBase
return Unauthorized("User not found (email-1)");
}
- var user = await _userManager.FindByIdAsync(principal.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? "");
+ var user = await userManager.FindByIdAsync(principal.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? string.Empty);
if (user == null)
{
return Unauthorized("User not found (email-2)");
@@ -85,20 +69,20 @@ public class AuthController : ControllerBase
// Check if the refresh token is valid.
// Remove any existing refresh tokens for this user and device.
var deviceIdentifier = GenerateDeviceIdentifier(Request);
- var existingToken = _context.AspNetUserRefreshTokens.Where(t => t.UserId == user.Id && t.DeviceIdentifier == deviceIdentifier).FirstOrDefault();
+ var existingToken = context.AspNetUserRefreshTokens.Where(t => t.UserId == user.Id && t.DeviceIdentifier == deviceIdentifier).FirstOrDefault();
if (existingToken == null || existingToken.Value != tokenModel.RefreshToken || existingToken.ExpireDate < DateTime.Now)
{
return Unauthorized("Refresh token expired");
}
// Remove the existing refresh token.
- _context.AspNetUserRefreshTokens.Remove(existingToken);
+ context.AspNetUserRefreshTokens.Remove(existingToken);
// Generate a new refresh token to replace the old one.
var newRefreshToken = GenerateRefreshToken();
// Add new refresh token.
- await _context.AspNetUserRefreshTokens.AddAsync(new AspNetUserRefreshToken
+ await context.AspNetUserRefreshTokens.AddAsync(new AspNetUserRefreshToken
{
UserId = user.Id,
DeviceIdentifier = deviceIdentifier,
@@ -106,11 +90,10 @@ public class AuthController : ControllerBase
ExpireDate = DateTime.Now.AddDays(30),
CreatedAt = DateTime.Now,
});
- await _context.SaveChangesAsync();
+ await context.SaveChangesAsync();
var token = GenerateJwtToken(user);
return Ok(new TokenModel() { Token = token, RefreshToken = newRefreshToken });
-
}
/// <summary>
@@ -127,7 +110,7 @@ public class AuthController : ControllerBase
return Unauthorized("User not found (email-1)");
}
- var user = await _userManager.FindByIdAsync(principal.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? string.Empty);
+ var user = await userManager.FindByIdAsync(principal.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? string.Empty);
if (user == null)
{
return Unauthorized("User not found (email-2)");
@@ -135,15 +118,15 @@ public class AuthController : ControllerBase
// Check if the refresh token is valid.
var deviceIdentifier = GenerateDeviceIdentifier(Request);
- var existingToken = _context.AspNetUserRefreshTokens.Where(t => t.UserId == user.Id && t.DeviceIdentifier == deviceIdentifier).FirstOrDefault();
+ var existingToken = context.AspNetUserRefreshTokens.Where(t => t.UserId == user.Id && t.DeviceIdentifier == deviceIdentifier).FirstOrDefault();
if (existingToken == null || existingToken.Value != model.RefreshToken)
{
return Unauthorized("Invalid refresh token");
}
// Remove the existing refresh token.
- _context.AspNetUserRefreshTokens.Remove(existingToken);
- await _context.SaveChangesAsync();
+ context.AspNetUserRefreshTokens.Remove(existingToken);
+ await context.SaveChangesAsync();
return Ok("Refresh token revoked successfully");
}
@@ -157,12 +140,12 @@ public class AuthController : ControllerBase
public async Task<IActionResult> Register([FromBody] RegisterModel model)
{
var user = new IdentityUser { UserName = model.Email, Email = model.Email };
- var result = await _userManager.CreateAsync(user, model.Password);
+ var result = await userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
// When a user is registered, they are automatically signed in.
- await _signInManager.SignInAsync(user, isPersistent: false);
+ await signInManager.SignInAsync(user, isPersistent: false);
// Return the token.
var tokenModel = await GenerateNewTokenForUser(user);
@@ -176,24 +159,23 @@ public class AuthController : ControllerBase
private string GenerateJwtToken(IdentityUser user)
{
- var claims = new[]
+ var claims = new List<Claim>
{
- new Claim(ClaimTypes.NameIdentifier, user.Id),
- new Claim(ClaimTypes.Name, user.UserName),
- new Claim(ClaimTypes.Email, user.Email),
- new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
+ new(ClaimTypes.NameIdentifier, user.Id ?? string.Empty),
+ new(ClaimTypes.Name, user.UserName ?? string.Empty),
+ new(ClaimTypes.Email, user.Email ?? string.Empty),
+ new(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
};
- var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Jwt:Key"]));
+ var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"] ?? string.Empty));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var token = new JwtSecurityToken(
- issuer: _configuration["Jwt:Issuer"],
- audience: _configuration["Jwt:Issuer"],
+ issuer: configuration["Jwt:Issuer"] ?? string.Empty,
+ audience: configuration["Jwt:Issuer"] ?? string.Empty,
claims: claims,
expires: DateTime.Now.AddMinutes(30),
- signingCredentials: creds
- );
+ signingCredentials: creds);
return new JwtSecurityTokenHandler().WriteToken(token);
}
@@ -201,11 +183,10 @@ public class AuthController : ControllerBase
private string GenerateRefreshToken()
{
var randomNumber = new byte[32];
- using (var rng = RandomNumberGenerator.Create())
- {
- rng.GetBytes(randomNumber);
- return Convert.ToBase64String(randomNumber);
- }
+ using var rng = RandomNumberGenerator.Create();
+
+ rng.GetBytes(randomNumber);
+ return Convert.ToBase64String(randomNumber);
}
private ClaimsPrincipal GetPrincipalFromExpiredToken(string token)
@@ -215,14 +196,13 @@ public class AuthController : ControllerBase
ValidateAudience = false,
ValidateIssuer = false,
ValidateIssuerSigningKey = true,
- IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Jwt:Key"])),
+ IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"] ?? string.Empty)),
ValidateLifetime = false,
};
var tokenHandler = new JwtSecurityTokenHandler();
var principal = tokenHandler.ValidateToken(token, tokenValidationParameters, out SecurityToken securityToken);
- var jwtSecurityToken = securityToken as JwtSecurityToken;
- if (jwtSecurityToken == null || !jwtSecurityToken.Header.Alg.Equals(SecurityAlgorithms.HmacSha256, StringComparison.InvariantCultureIgnoreCase))
+ if (securityToken is not JwtSecurityToken jwtSecurityToken || !jwtSecurityToken.Header.Alg.Equals(SecurityAlgorithms.HmacSha256, StringComparison.InvariantCultureIgnoreCase))
{
throw new SecurityTokenException("Invalid token");
}
@@ -233,8 +213,8 @@ public class AuthController : ControllerBase
private string GenerateDeviceIdentifier(HttpRequest request)
{
// TODO: Add more headers to the device identifier or let client send a unique identifier instead.
- var userAgent = request.Headers["User-Agent"].ToString();
- var acceptLanguage = request.Headers["Accept-Language"].ToString();
+ var userAgent = request.Headers.UserAgent.ToString();
+ var acceptLanguage = request.Headers.AcceptLanguage.ToString();
var rawIdentifier = $"{userAgent}|{acceptLanguage}";
return rawIdentifier;
@@ -250,11 +230,11 @@ public class AuthController : ControllerBase
// Save refresh token to database.
// Remove any existing refresh tokens for this user and device.
- var existingTokens = _context.AspNetUserRefreshTokens.Where(t => t.UserId == user.Id && t.DeviceIdentifier == deviceIdentifier);
- _context.AspNetUserRefreshTokens.RemoveRange(existingTokens);
+ var existingTokens = context.AspNetUserRefreshTokens.Where(t => t.UserId == user.Id && t.DeviceIdentifier == deviceIdentifier);
+ context.AspNetUserRefreshTokens.RemoveRange(existingTokens);
// Add new refresh token.
- await _context.AspNetUserRefreshTokens.AddAsync(new AspNetUserRefreshToken
+ await context.AspNetUserRefreshTokens.AddAsync(new AspNetUserRefreshToken
{
UserId = user.Id,
DeviceIdentifier = deviceIdentifier,
@@ -262,7 +242,7 @@ public class AuthController : ControllerBase
ExpireDate = DateTime.Now.AddDays(30),
CreatedAt = DateTime.Now,
});
- await _context.SaveChangesAsync();
+ await context.SaveChangesAsync();
return new TokenModel() { Token = token, RefreshToken = refreshToken };
}
diff --git a/src/AliasVault.Api/Controllers/AuthenticatedRequestController.cs b/src/AliasVault.Api/Controllers/AuthenticatedRequestController.cs
index 62c056367..c8c5e68ac 100644
--- a/src/AliasVault.Api/Controllers/AuthenticatedRequestController.cs
+++ b/src/AliasVault.Api/Controllers/AuthenticatedRequestController.cs
@@ -14,34 +14,22 @@ using Microsoft.AspNetCore.Mvc;
/// <summary>
/// Base controller for requests that require authentication.
/// </summary>
+/// <remarks>
+/// Initializes a new instance of the <see cref="AuthenticatedRequestController"/> class.
+/// </remarks>
+/// <param name="userManager">UserManager instance.</param>
[Route("api/[controller]")]
[ApiController]
[Authorize]
-public class AuthenticatedRequestController : ControllerBase
+public class AuthenticatedRequestController(UserManager<IdentityUser> userManager) : ControllerBase
{
- private readonly UserManager<IdentityUser> _userManager;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AuthenticatedRequestController"/> class.
- /// </summary>
- /// <param name="userManager">UserManager instance.</param>
- public AuthenticatedRequestController(UserManager<IdentityUser> userManager)
- {
- _userManager = userManager;
- }
-
/// <summary>
/// Get the current authenticated user.
/// </summary>
/// <returns>IdentityUser object for current user.</returns>
protected async Task<IdentityUser?> GetCurrentUserAsync()
{
- var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
- if (userId == null)
- {
- throw new InvalidOperationException("Unable to find user ID.");
- }
-
- return await _userManager.FindByIdAsync(userId);
+ var userId = User.FindFirstValue(ClaimTypes.NameIdentifier) ?? throw new InvalidOperationException("Unable to find user ID.");
+ return await userManager.FindByIdAsync(userId);
}
}
diff --git a/src/AliasVault.Api/Controllers/IdentityController.cs b/src/AliasVault.Api/Controllers/IdentityController.cs
index bb244ff32..068fb3f57 100644
--- a/src/AliasVault.Api/Controllers/IdentityController.cs
+++ b/src/AliasVault.Api/Controllers/IdentityController.cs
@@ -14,20 +14,13 @@ using Microsoft.AspNetCore.Mvc;
/// <summary>
/// Controller for identity generation.
/// </summary>
-public class IdentityController : AuthenticatedRequestController
+/// <param name="userManager">UserManager instance.</param>
+public class IdentityController(UserManager<IdentityUser> userManager) : AuthenticatedRequestController(userManager)
{
- /// <summary>
- /// Initializes a new instance of the <see cref="IdentityController"/> class.
- /// </summary>
- /// <param name="userManager">UserManager instance.</param>
- public IdentityController(UserManager<IdentityUser> userManager) : base(userManager)
- {
- }
-
/// <summary>
/// Proxies the request to the identity generator to generate a random identity.
/// </summary>
- /// <returns></returns>
+ /// <returns>Identity model.</returns>
[HttpGet("generate")]
public async Task<IActionResult> Generate()
{
diff --git a/src/AliasVault.Api/Program.cs b/src/AliasVault.Api/Program.cs
index 6119af47e..9a213e651 100644
--- a/src/AliasVault.Api/Program.cs
+++ b/src/AliasVault.Api/Program.cs
@@ -83,7 +83,7 @@ builder.Services.AddAuthentication(options =>
ValidateIssuerSigningKey = true,
ValidIssuer = configuration["Jwt:Issuer"],
ValidAudience = configuration["Jwt:Issuer"],
- IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"])),
+ IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"] ?? string.Empty)),
ClockSkew = TimeSpan.Zero,
};
});
diff --git a/src/AliasVault.Shared/Models/LoginModel.cs b/src/AliasVault.Shared/Models/LoginModel.cs
index 334b0b932..a6c25e221 100644
--- a/src/AliasVault.Shared/Models/LoginModel.cs
+++ b/src/AliasVault.Shared/Models/LoginModel.cs
@@ -1,7 +1,24 @@
+//-----------------------------------------------------------------------
+// <copyright file="LoginModel.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
namespace AliasVault.Shared.Models;
+/// <summary>
+/// Login model.
+/// </summary>
public class LoginModel
{
- public string Email { get; set; }
- public string Password { get; set; }
+ /// <summary>
+ /// Gets or sets the email.
+ /// </summary>
+ public string Email { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the password.
+ /// </summary>
+ public string Password { get; set; } = null!;
}
diff --git a/src/AliasVault.Shared/Models/RegisterModel.cs b/src/AliasVault.Shared/Models/RegisterModel.cs
index 3d5850113..719288875 100644
--- a/src/AliasVault.Shared/Models/RegisterModel.cs
+++ b/src/AliasVault.Shared/Models/RegisterModel.cs
@@ -1,9 +1,34 @@
+//-----------------------------------------------------------------------
+// <copyright file="RegisterModel.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
namespace AliasVault.Shared.Models;
+/// <summary>
+/// Register model.
+/// </summary>
public class RegisterModel
{
- public string Email { get; set; }
- public string Password { get; set; }
- public string PasswordConfirm { get; set; }
- public bool AcceptTerms { get; set; }
+ /// <summary>
+ /// Gets or sets the email.
+ /// </summary>
+ public string Email { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the password.
+ /// </summary>
+ public string Password { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the password confirmation.
+ /// </summary>
+ public string PasswordConfirm { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the terms and conditions are accepted or not.
+ /// </summary>
+ public bool AcceptTerms { get; set; } = false;
}
diff --git a/src/AliasVault.Shared/Models/TokenModel.cs b/src/AliasVault.Shared/Models/TokenModel.cs
index 6e78a28a0..696c717f3 100644
--- a/src/AliasVault.Shared/Models/TokenModel.cs
+++ b/src/AliasVault.Shared/Models/TokenModel.cs
@@ -1,12 +1,28 @@
+//-----------------------------------------------------------------------
+// <copyright file="TokenModel.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
using System.Text.Json.Serialization;
namespace AliasVault.Shared.Models;
+/// <summary>
+/// Token model.
+/// </summary>
public class TokenModel
{
+ /// <summary>
+ /// Gets or sets the token.
+ /// </summary>
[JsonPropertyName("token")]
- public string Token { get; set; }
+ public string Token { get; set; } = null!;
+ /// <summary>
+ /// Gets or sets the refresh token.
+ /// </summary>
[JsonPropertyName("refreshToken")]
- public string RefreshToken { get; set; }
+ public string RefreshToken { get; set; } = null!;
}
diff --git a/src/AliasVault.Shared/Models/WebApi/Alias.cs b/src/AliasVault.Shared/Models/WebApi/Alias.cs
index 07eb7bb10..15315256f 100644
--- a/src/AliasVault.Shared/Models/WebApi/Alias.cs
+++ b/src/AliasVault.Shared/Models/WebApi/Alias.cs
@@ -1,10 +1,39 @@
+//-----------------------------------------------------------------------
+// <copyright file="Alias.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
namespace AliasVault.Shared.Models.WebApi;
+/// <summary>
+/// Alias model.
+/// </summary>
public class Alias
{
- public Service Service { get; set; }
- public Identity Identity { get; set; }
- public Password Password { get; set; }
+ /// <summary>
+ /// Gets or sets the Alias Service object.
+ /// </summary>
+ public Service Service { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the Alias Identity object.
+ /// </summary>
+ public Identity Identity { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the Alias Password object.
+ /// </summary>
+ public Password Password { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the Alias CreateDate.
+ /// </summary>
public DateTime CreateDate { get; set; }
+
+ /// <summary>
+ /// Gets or sets the Alias LastUpdate.
+ /// </summary>
public DateTime LastUpdate { get; set; }
}
diff --git a/src/AliasVault.Shared/Models/WebApi/AliasListEntry.cs b/src/AliasVault.Shared/Models/WebApi/AliasListEntry.cs
index 83065c0df..a1746d91e 100644
--- a/src/AliasVault.Shared/Models/WebApi/AliasListEntry.cs
+++ b/src/AliasVault.Shared/Models/WebApi/AliasListEntry.cs
@@ -1,9 +1,34 @@
+//-----------------------------------------------------------------------
+// <copyright file="AliasListEntry.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
namespace AliasVault.Shared.Models.WebApi;
+/// <summary>
+/// Alias list entry model. This model is used to represent an alias in a list with simplified properties.
+/// </summary>
public class AliasListEntry
{
+ /// <summary>
+ /// Gets or sets the alias id.
+ /// </summary>
public Guid Id { get; set; }
- public byte[] Logo { get; set; }
- public string Service { get; set; }
+
+ /// <summary>
+ /// Gets or sets the alias logo byte array.
+ /// </summary>
+ public byte[]? Logo { get; set; }
+
+ /// <summary>
+ /// Gets or sets the alias service name.
+ /// </summary>
+ public string Service { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the alias create date.
+ /// </summary>
public DateTime CreateDate { get; set; }
}
diff --git a/src/AliasVault.Shared/Models/WebApi/Identity.cs b/src/AliasVault.Shared/Models/WebApi/Identity.cs
index 7a508cdb7..a610e88ea 100644
--- a/src/AliasVault.Shared/Models/WebApi/Identity.cs
+++ b/src/AliasVault.Shared/Models/WebApi/Identity.cs
@@ -1,23 +1,104 @@
+//-----------------------------------------------------------------------
+// <copyright file="Identity.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
namespace AliasVault.Shared.Models.WebApi;
+/// <summary>
+/// Identity model.
+/// </summary>
public class Identity
{
+ /// <summary>
+ /// Gets or sets the identity id.
+ /// </summary>
public Guid Id { get; set; }
- public string Gender { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string NickName { get; set; }
- public string BirthDate { get; set; }
- public string AddressStreet { get; set; }
- public string AddressCity { get; set; }
+
+ /// <summary>
+ /// Gets or sets the gender.
+ /// </summary>
+ public string? Gender { get; set; }
+
+ /// <summary>
+ /// Gets or sets the first name.
+ /// </summary>
+ public string? FirstName { get; set; }
+
+ /// <summary>
+ /// Gets or sets the last name.
+ /// </summary>
+ public string? LastName { get; set; }
+
+ /// <summary>
+ /// Gets or sets the nickname.
+ /// </summary>
+ public string? NickName { get; set; }
+
+ /// <summary>
+ /// Gets or sets the birth date.
+ /// </summary>
+ public string? BirthDate { get; set; }
+
+ /// <summary>
+ /// Gets or sets the street address.
+ /// </summary>
+ public string? AddressStreet { get; set; }
+
+ /// <summary>
+ /// Gets or sets the city.
+ /// </summary>
+ public string? AddressCity { get; set; }
+
+ /// <summary>
+ /// Gets or sets the state.
+ /// </summary>
public string? AddressState { get; set; }
- public string AddressZipCode { get; set; }
- public string AddressCountry { get; set; }
- public string Hobbies { get; set; }
- public string EmailPrefix { get; set; }
- public string PhoneMobile { get; set; }
- public string BankAccountIBAN { get; set; }
+
+ /// <summary>
+ /// Gets or sets the zip code.
+ /// </summary>
+ public string? AddressZipCode { get; set; }
+
+ /// <summary>
+ /// Gets or sets the country.
+ /// </summary>
+ public string? AddressCountry { get; set; }
+
+ /// <summary>
+ /// Gets or sets the hobbies.
+ /// </summary>
+ public string? Hobbies { get; set; }
+
+ /// <summary>
+ /// Gets or sets the email prefix.
+ /// </summary>
+ public string? EmailPrefix { get; set; }
+
+ /// <summary>
+ /// Gets or sets the mobile phone number.
+ /// </summary>
+ public string? PhoneMobile { get; set; }
+
+ /// <summary>
+ /// Gets or sets the bank account IBAN.
+ /// </summary>
+ public string? BankAccountIBAN { get; set; }
+
+ /// <summary>
+ /// Gets or sets the date and time of creation.
+ /// </summary>
public DateTime CreatedAt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the date and time of last update.
+ /// </summary>
public DateTime UpdatedAt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the default password.
+ /// </summary>
public Password? DefaultPassword { get; set; }
}
diff --git a/src/AliasVault.Shared/Models/WebApi/Password.cs b/src/AliasVault.Shared/Models/WebApi/Password.cs
index 114ecb632..a7f38b531 100644
--- a/src/AliasVault.Shared/Models/WebApi/Password.cs
+++ b/src/AliasVault.Shared/Models/WebApi/Password.cs
@@ -1,9 +1,34 @@
+//-----------------------------------------------------------------------
+// <copyright file="Password.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
namespace AliasVault.Shared.Models.WebApi;
+/// <summary>
+/// Password model.
+/// </summary>
public class Password
{
- public string Value { get; set; }
+ /// <summary>
+ /// Gets or sets the value of the password.
+ /// </summary>
+ public string Value { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the description of the password.
+ /// </summary>
public string? Description { get; set; }
+
+ /// <summary>
+ /// Gets or sets the date and time when the password was created.
+ /// </summary>
public DateTime CreatedAt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the date and time when the password was last updated.
+ /// </summary>
public DateTime UpdatedAt { get; set; }
}
diff --git a/src/AliasVault.Shared/Models/WebApi/Service.cs b/src/AliasVault.Shared/Models/WebApi/Service.cs
index dd48d1533..15b30d82d 100644
--- a/src/AliasVault.Shared/Models/WebApi/Service.cs
+++ b/src/AliasVault.Shared/Models/WebApi/Service.cs
@@ -1,11 +1,44 @@
+//-----------------------------------------------------------------------
+// <copyright file="Service.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
namespace AliasVault.Shared.Models.WebApi;
+/// <summary>
+/// Service model.
+/// </summary>
public class Service
{
- public string Name { get; set; }
+ /// <summary>
+ /// Gets or sets the name of the service.
+ /// </summary>
+ public string Name { get; set; } = null!;
+
+ /// <summary>
+ /// Gets or sets the description of the service.
+ /// </summary>
public string? Description { get; set; }
+
+ /// <summary>
+ /// Gets or sets the URL of the service.
+ /// </summary>
public string? Url { get; set; }
+
+ /// <summary>
+ /// Gets or sets the logo URL of the service.
+ /// </summary>
public string? LogoUrl { get; set; }
+
+ /// <summary>
+ /// Gets or sets the creation date and time of the service.
+ /// </summary>
public DateTime CreatedAt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the last updated date and time of the service.
+ /// </summary>
public DateTime UpdatedAt { get; set; }
}