Compare commits

..

2 Commits

Author SHA1 Message Date
max
5c4ebd2b32 [ADD] Added verifiers, validators & config. 2024-12-23 01:26:21 +01:00
max
797323789e [ADD] Added base options 2024-12-23 00:59:13 +01:00
22 changed files with 124 additions and 20 deletions

View File

@ -1,12 +1,16 @@
using DotBased.AspNet.Authority.Interfaces;
using DotBased.AspNet.Authority.Models.Options;
using Microsoft.Extensions.DependencyInjection;
namespace DotBased.AspNet.Authority;
public static class AuthorityProviderExtensions
{
public static AuthorityBuilder AddAuthorityProvider<TModel>(this IServiceCollection services) where TModel : class
public static AuthorityBuilder AddAuthorityProvider<TModel>(this IServiceCollection services, Action<AuthorityOptions> optionsAction) where TModel : class
{
services.AddOptions();
// Configure required classes, services, etc.
services.Configure<AuthorityOptions>(optionsAction);
return new AuthorityBuilder(services);
}

View File

@ -21,4 +21,8 @@
<Folder Include="Models\Security\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0" />
</ItemGroup>
</Project>

View File

@ -1,7 +0,0 @@
namespace DotBased.AspNet.Authority.Interfaces;
public interface ISecurityVersionRepository<in TRepositoryObject>
{
public Task<long> GetSecurityVersionAsync(TRepositoryObject obj);
}

View File

@ -1,8 +1,9 @@
namespace DotBased.AspNet.Authority.Interfaces;
public interface IUserRepository<TUser, TId> : IVersionRepository<TUser>, ISecurityVersionRepository<TUser> where TUser : class where TId : IEquatable<TId>
public interface IUserRepository<TUser, TId> where TUser : class where TId : IEquatable<TId>
{
public Task<TUser?> GetUserByIdAsync(TId id);
public Task<TId> GetUserIdAsync(TUser user);
public Task SetVersion(TUser user, long version);
public Task SetSecurityVersion(TUser user, long version);
}

View File

@ -1,6 +0,0 @@
namespace DotBased.AspNet.Authority.Interfaces;
public interface IVersionRepository<in TRepositoryObject>
{
public Task<long> GetVersionAsync(TRepositoryObject obj);
}

View File

@ -2,7 +2,7 @@ namespace DotBased.AspNet.Authority.Models.Authority;
public class AuthorityAttribute
{
public AuthorityAttribute(string attributeKey, string bound) : this()
public AuthorityAttribute(string attributeKey, string bound)
{
AttributeKey = attributeKey;
BoundId = bound;
@ -10,14 +10,15 @@ public class AuthorityAttribute
public AuthorityAttribute()
{
AttributeKey = string.Empty;
BoundId = string.Empty;
}
public string AttributeKey { get; set; } // ClaimType/Authority.attribute.enabled
public string BoundId { get; set; } // Bound to User, Group, Role id
public string? AttributeValue { get; set; }
public object? AttributeValue { get; set; }
public string? Type { get; set; } // AspNet.Claim.Role/Property/Data.JSON, Data.Raw, Data.Base64 etc.

View File

@ -22,6 +22,8 @@ public abstract class AuthorityUser<TKey> where TKey : IEquatable<TKey>
public bool Enabled { get; set; }
public bool Confirmed { get; set; }
public bool Locked { get; set; }
public DateTime LockedDate { get; set; }

View File

@ -0,0 +1,10 @@
namespace DotBased.AspNet.Authority.Models.Options;
public class AuthorityOptions
{
public LockdownOptions Lockdown { get; set; } = new();
public LockoutOptions Lockout { get; set; } = new();
public PasswordOptions Password { get; set; } = new();
public ProviderOptions Provider { get; set; } = new();
public UserOptions User { get; set; } = new();
}

View File

@ -0,0 +1,6 @@
namespace DotBased.AspNet.Authority.Models.Options;
public class LockdownOptions
{
public bool EnableLockout { get; set; }
}

View File

@ -0,0 +1,8 @@
namespace DotBased.AspNet.Authority.Models.Options;
public class LockoutOptions
{
public bool EnableLockout { get; set; } = true;
public int FailedAttempts { get; set; } = 3;
public TimeSpan LockoutTimeout { get; set; } = TimeSpan.FromMinutes(30);
}

View File

@ -0,0 +1,14 @@
namespace DotBased.AspNet.Authority.Models.Options;
public class PasswordOptions
{
public int RequiredLength { get; set; } = 10;
public int MinimalUniqueChars { get; set; } = 1;
public bool RequireLowercase { get; set; }
public bool RequireUppercase { get; set; }
public bool RequireDigit { get; set; }
public bool RequireNonAlphanumeric { get; set; }
public List<string> PasswordBlackList { get; set; } = ["password", "1234"];
public StringComparer PasswordBlackListComparer { get; set; } = StringComparer.OrdinalIgnoreCase;
}

View File

@ -0,0 +1,6 @@
namespace DotBased.AspNet.Authority.Models.Options;
public class ProviderOptions
{
}

View File

@ -0,0 +1,8 @@
namespace DotBased.AspNet.Authority.Models.Options;
public class SignInOptions
{
public bool RequireVerifiedEmail { get; set; }
public bool RequireVerifiedPhoneNumber { get; set; }
public bool RequireConfirmedAccount { get; set; }
}

View File

@ -0,0 +1,11 @@
namespace DotBased.AspNet.Authority.Models.Options;
public class UserOptions
{
public bool EnableRegister { get; set; }
public bool RequireUniqueEmail { get; set; }
public string AllowedCharacters { get; set; } = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@";
public List<string> UserNameBlackList { get; set; } = ["admin", "administrator", "dev", "developer"];
public StringComparer UserNameBlackListComparer { get; set; } = StringComparer.OrdinalIgnoreCase;
}

View File

@ -1,6 +1,6 @@
namespace DotBased.AspNet.Authority.Services;
public class AuthorityService
public class AuthorityManager<TData>
{
public long GenerateVersion() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
}

View File

@ -0,0 +1,6 @@
namespace DotBased.AspNet.Authority.Validators;
public interface IPasswordValidator<TUser>
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.AspNet.Authority.Validators;
public interface IUserValidator
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.AspNet.Authority.Validators;
public class PasswordValidator
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.AspNet.Authority.Validators;
public class UserValidator
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.AspNet.Authority.Verifiers;
public interface IEmailVerifier
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.AspNet.Authority.Verifiers;
public interface IPhoneNumberVerifier
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.AspNet.Authority.Verifiers;
public class IUserVerifier
{
}