Files
2026-06-26 10:29:23 +02:00

90 lines
3.4 KiB
C#

using adas_core.Domain.Models.MongoModels;
namespace adas_core.Domain.Models.AppSettings;
/// <summary>
/// Represents a set of configuration settings used to control authentication behavior.
/// </summary>
public class AuthSettings
{
public JwtConfig? JwtConfig { get; set; }
public UsersWhiteListConfig UsersWhiteListConfig { get; set; } = [];
public List<string> LoginMethods { get; set; } = [];
}
/// <summary>
/// Represents a JWT configuration class that extends <see cref="JwtExtConfig"/>, providing additional or specialized settings for JSON Web Token processing.
/// </summary>
/// <remarks>
/// This class derives from <see cref="JwtExtConfig"/> and inherits its configuration properties, allowing it to serve as a more specific or customized JWT configuration type.
/// </remarks>
public class JwtConfig : JwtExtConfig
{
public string? Issuer { get; set; }
public bool ValidateIssuer { get; set; } = true;
public int TokenValidityInMinutes { get; set; } = 10;
public int RefreshTokenValidityInMinutes { get; set; } = 1440;
public Dictionary<string, JwtExtConfig>? ExternalProviders { get; set; } = null;
}
/// <summary>
/// Represents a configuration class for JWT (JSON Web Token) extension settings.
/// </summary>
public class JwtExtConfig
{
public string? Key { get; set; }
public string? Audience { get; set; }
public bool ValidateAudience { get; set; } = true;
}
/// <summary>
/// Represents a configuration collection that defines a whitelist of users, stored as a list of string identifiers.
/// </summary>
/// <remarks>
/// Inherits from a generic list of strings, exposing standard collection semantics for the whitelisted user entries.
/// </remarks>
public class UsersWhiteListConfig : List<string>
{
/// <summary>
/// Determines whether the collection contains a username matching the specified user's username, using a case-insensitive comparison.
/// </summary>
/// <param name="user">The user whose username will be checked against the collection.</param>
/// <returns><c>true</c> if a matching username is found; otherwise, <c>false</c>.</returns>
public bool IsValid(User user)
{
return this.Any(username => username.ToLowerInvariant().Equals(user.UserName.ToLowerInvariant()));
}
}
/// <summary>
/// Represents a configuration collection of <see cref="ValidGroup"/> instances, exposing them as a strongly-typed list.
/// </summary>
/// <remarks>
/// This type inherits from <see cref="List{T}"/> where T is <see cref="ValidGroup"/>, providing standard list operations for managing the configured valid groups.
/// </remarks>
/// <summary>
/// Represents a validation group used to organize or aggregate related validation rules.
/// </summary>
/// <remarks>
/// This type serves as a container or marker for grouping validation logic within a broader validation framework.
/// </remarks>
public class ValidGroupsConfig : List<ValidGroup>
{
/// <summary>
/// Determines whether the specified user is considered valid by checking that it is not null.
/// </summary>
/// <param name="user">The user instance to validate.</param>
/// <returns><see langword="true"/> if <paramref name="user"/> is not null; otherwise, <see langword="false"/>.</returns>
public bool IsValid(User? user)
{
return user != null;
}
}
public class ValidGroup
{
public string? Name { get; set; }
public bool IsRegex { get; set; } = false;
}