Implementing ASP auth module
This commit is contained in:
6
DotBased.ASP.Auth/AuthService.cs
Normal file
6
DotBased.ASP.Auth/AuthService.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Auth;
|
||||
|
||||
public class AuthService
|
||||
{
|
||||
|
||||
}
|
18
DotBased.ASP.Auth/BasedAuthConfiguration.cs
Normal file
18
DotBased.ASP.Auth/BasedAuthConfiguration.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace DotBased.ASP.Auth;
|
||||
|
||||
public class BasedAuthConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Allow users to registrate a user account.
|
||||
/// </summary>
|
||||
public bool AllowRegistration { get; set; }
|
||||
//TODO: Callback when a user registers, so the application can handle sending emails or generate a code to complete the registration.
|
||||
public string LoginPath { get; set; } = string.Empty;
|
||||
public string LogoutPath { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// The max age before a AuthenticationState will expire (default: 7 days).
|
||||
/// </summary>
|
||||
public TimeSpan AuthenticationStateMaxAgeBeforeExpire { get; set; } = TimeSpan.FromDays(7);
|
||||
//TODO: Data seeding
|
||||
public Action<AuthService>? SeedData { get; set; }
|
||||
}
|
20
DotBased.ASP.Auth/BasedAuthenticationStateProvider.cs
Normal file
20
DotBased.ASP.Auth/BasedAuthenticationStateProvider.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using DotBased.Logging;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
|
||||
namespace DotBased.ASP.Auth;
|
||||
|
||||
public class BasedAuthenticationStateProvider : AuthenticationStateProvider
|
||||
{
|
||||
public BasedAuthenticationStateProvider()
|
||||
{
|
||||
_logger = LogService.RegisterLogger(typeof(BasedAuthenticationStateProvider));
|
||||
}
|
||||
|
||||
private ILogger _logger;
|
||||
|
||||
public override Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||
{
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Auth.Domains.Auth;
|
||||
|
||||
public class AuthenticationStateModel
|
||||
{
|
||||
|
||||
}
|
8
DotBased.ASP.Auth/Domains/Auth/PermissionModel.cs
Normal file
8
DotBased.ASP.Auth/Domains/Auth/PermissionModel.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace DotBased.ASP.Auth.Domains.Auth;
|
||||
|
||||
public class PermissionModel
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Permission { get; set; } = string.Empty;
|
||||
}
|
9
DotBased.ASP.Auth/Domains/Auth/RoleModel.cs
Normal file
9
DotBased.ASP.Auth/Domains/Auth/RoleModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace DotBased.ASP.Auth.Domains.Auth;
|
||||
|
||||
public class RoleModel
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public List<PermissionModel> Permissions { get; set; } = [];
|
||||
}
|
8
DotBased.ASP.Auth/Domains/Identity/GroupItemModel.cs
Normal file
8
DotBased.ASP.Auth/Domains/Identity/GroupItemModel.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace DotBased.ASP.Auth.Domains.Identity;
|
||||
|
||||
public class GroupItemModel
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
}
|
11
DotBased.ASP.Auth/Domains/Identity/GroupModel.cs
Normal file
11
DotBased.ASP.Auth/Domains/Identity/GroupModel.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using DotBased.ASP.Auth.Domains.Auth;
|
||||
|
||||
namespace DotBased.ASP.Auth.Domains.Identity;
|
||||
|
||||
public class GroupModel
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public List<RoleModel> Roles { get; set; } = [];
|
||||
}
|
10
DotBased.ASP.Auth/Domains/Identity/UserItemModel.cs
Normal file
10
DotBased.ASP.Auth/Domains/Identity/UserItemModel.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace DotBased.ASP.Auth.Domains.Identity;
|
||||
|
||||
public class UserItemModel
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string FamilyName { get; set; } = string.Empty;
|
||||
}
|
14
DotBased.ASP.Auth/Domains/Identity/UserModel.cs
Normal file
14
DotBased.ASP.Auth/Domains/Identity/UserModel.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace DotBased.ASP.Auth.Domains.Identity;
|
||||
|
||||
public class UserModel
|
||||
{
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string FamilyName { get; set; } = string.Empty;
|
||||
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public string PasswordHash { get; set; } = string.Empty;
|
||||
public string[] GroupIds { get; set; } = Array.Empty<string>();
|
||||
public string[] Roles { get; set; } = Array.Empty<string>();
|
||||
}
|
8
DotBased.ASP.Auth/Domains/LoginModel.cs
Normal file
8
DotBased.ASP.Auth/Domains/LoginModel.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace DotBased.ASP.Auth.Domains;
|
||||
|
||||
public class LoginModel
|
||||
{
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
10
DotBased.ASP.Auth/Domains/RegisterModel.cs
Normal file
10
DotBased.ASP.Auth/Domains/RegisterModel.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace DotBased.ASP.Auth.Domains;
|
||||
|
||||
public class RegisterModel
|
||||
{
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string FamilyName { get; set; } = string.Empty;
|
||||
}
|
20
DotBased.ASP.Auth/DotBased.ASP.Auth.csproj
Normal file
20
DotBased.ASP.Auth/DotBased.ASP.Auth.csproj
Normal file
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DotBased\DotBased.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
</Project>
|
13
DotBased.ASP.Auth/DotBasedASPAuth.cs
Normal file
13
DotBased.ASP.Auth/DotBasedASPAuth.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DotBased.ASP.Auth;
|
||||
|
||||
public static class DotBasedASPAuth
|
||||
{
|
||||
public static void UseBasedAuth(this WebApplicationBuilder builder, BasedAuthConfiguration configuration)
|
||||
{
|
||||
builder.Services.AddScoped<AuthenticationStateProvider, BasedAuthenticationStateProvider>();
|
||||
}
|
||||
}
|
38
DotBased.ASP.Auth/IAuthDataProvider.cs
Normal file
38
DotBased.ASP.Auth/IAuthDataProvider.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using DotBased.ASP.Auth.Domains.Auth;
|
||||
using DotBased.ASP.Auth.Domains.Identity;
|
||||
|
||||
namespace DotBased.ASP.Auth;
|
||||
|
||||
public interface IAuthDataProvider
|
||||
{
|
||||
/*
|
||||
* Identity
|
||||
*/
|
||||
|
||||
// User
|
||||
public Task<Result> CreateUserAsync(UserModel user);
|
||||
public Task<Result> UpdateUserAsync(UserModel user);
|
||||
public Task<Result> DeleteUserAsync(UserModel user);
|
||||
public Task<Result<UserModel>> GetUserAsync(string id, string email, string username);
|
||||
public Task<ListResult<UserItemModel>> GetUsersAsync(int start = 0, int amount = 30, string search = "");
|
||||
|
||||
// Group
|
||||
public Task<Result> CreateGroupAsync(GroupModel group);
|
||||
public Task<Result> UpdateGroupAsync(GroupModel group);
|
||||
public Task<Result> DeleteGroupAsync(GroupModel group);
|
||||
public Task<Result<GroupModel>> GetGroupAsync(string id);
|
||||
public Task<ListResult<GroupItemModel>> GetGroupsAsync(int start = 0, int amount = 30, string search = "");
|
||||
|
||||
/*
|
||||
* Auth
|
||||
*/
|
||||
|
||||
// AuthenticationState
|
||||
public Task<Result> CreateAuthenticationStateAsync(AuthenticationStateModel authenticationState);
|
||||
public Task<Result> UpdateAuthenticationStateAsync(AuthenticationStateModel authenticationState);
|
||||
public Task<Result> DeleteAuthenticationStateAsync(AuthenticationStateModel authenticationState);
|
||||
public Task<Result<AuthenticationStateModel>> GetAuthenticationStateAsync(string id);
|
||||
|
||||
// Authorization
|
||||
|
||||
}
|
Reference in New Issue
Block a user