Merge remote-tracking branch 'origin/main'

This commit is contained in:
max 2024-12-16 02:34:51 +01:00
commit e62bdfeeae
14 changed files with 91 additions and 4 deletions

View File

@ -0,0 +1,13 @@
namespace DotBased.ASP.Auth.Services;
public class AuthenticationService
{
public AuthenticationService()
{
/*
* - Login
* - Logout
* - Register
*/
}
}

View File

@ -48,3 +48,18 @@ public class BasedAuthConfiguration
where TSessionStateProviderType : ISessionStateProvider => where TSessionStateProviderType : ISessionStateProvider =>
SessionStateProviderType = typeof(TSessionStateProviderType); SessionStateProviderType = typeof(TSessionStateProviderType);
} }
public class BasedPasswordOptions
{
}
public class BasedUserOptions
{
}
public class BasedLockoutOptions
{
}

View File

@ -1,5 +1,4 @@
using System.Security.Claims; using System.Security.Claims;
using DotBased.ASP.Auth.Services;
using DotBased.Logging; using DotBased.Logging;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server; using Microsoft.AspNetCore.Components.Server;

View File

@ -13,4 +13,9 @@
<ItemGroup> <ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" /> <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Models\Auth\States\" />
<Folder Include="Models\Repositories\" />
</ItemGroup>
</Project> </Project>

View File

@ -18,7 +18,6 @@ public static class DotBasedAuthDependencyInjection
var Configuration = new BasedAuthConfiguration(); var Configuration = new BasedAuthConfiguration();
configurationAction?.Invoke(Configuration); configurationAction?.Invoke(Configuration);
services.AddSingleton<BasedAuthConfiguration>(Configuration); services.AddSingleton<BasedAuthConfiguration>(Configuration);
if (Configuration.AuthDataRepositoryType == null) if (Configuration.AuthDataRepositoryType == null)
throw new ArgumentNullException(nameof(Configuration.AuthDataRepositoryType), $"No '{nameof(IAuthDataRepository)}' configured!"); throw new ArgumentNullException(nameof(Configuration.AuthDataRepositoryType), $"No '{nameof(IAuthDataRepository)}' configured!");

View File

@ -0,0 +1,11 @@
namespace DotBased.ASP.Auth.Models.Configuration;
public class AuthConfiguration
{
public CacheConfiguration Cache { get; set; } = new();
public LockoutConfiguration Lockout { get; set; } = new();
public PasswordConfiguration Password { get; set; } = new();
public ProviderConfiguration Provider { get; set; } = new();
public RepositoryConfiguration Repository { get; set; } = new();
public UserConfiguration User { get; set; } = new();
}

View File

@ -0,0 +1,6 @@
namespace DotBased.ASP.Auth.Models.Configuration;
public class CacheConfiguration
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.ASP.Auth.Models.Configuration;
public class LockoutConfiguration
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.ASP.Auth.Models.Configuration;
public class PasswordConfiguration
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.ASP.Auth.Models.Configuration;
public class ProviderConfiguration
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.ASP.Auth.Models.Configuration;
public class RepositoryConfiguration
{
}

View File

@ -0,0 +1,6 @@
namespace DotBased.ASP.Auth.Models.Configuration;
public class UserConfiguration
{
}

View File

@ -0,0 +1,9 @@
namespace DotBased.ASP.Auth.Managers;
public class SecurityManager
{
public SecurityManager()
{
}
}

View File

@ -7,7 +7,7 @@ using DotBased.Logging;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
namespace DotBased.ASP.Auth.Services; namespace DotBased.ASP.Auth;
public class SecurityService public class SecurityService
{ {
@ -60,9 +60,9 @@ public class SecurityService
new(ClaimTypes.Surname, userResult.Value.FamilyName), new(ClaimTypes.Surname, userResult.Value.FamilyName),
new(ClaimTypes.Email, userResult.Value.Email) new(ClaimTypes.Email, userResult.Value.Email)
}; };
//TODO: combine group, user roles
claims.AddRange(userResult.Value.Groups.Select(group => new Claim(ClaimTypes.GroupSid, group.Id))); claims.AddRange(userResult.Value.Groups.Select(group => new Claim(ClaimTypes.GroupSid, group.Id)));
claims.AddRange(userResult.Value.Roles.Select(role => new Claim(ClaimTypes.Role, role.Name))); claims.AddRange(userResult.Value.Roles.Select(role => new Claim(ClaimTypes.Role, role.Name)));
claims.AddRange(userResult.Value.Groups.Select(g => g.Roles).SelectMany(gRolesList => gRolesList, (_, role) => new Claim(ClaimTypes.Role, role.Name)));
var claimsIdentity = new ClaimsIdentity(claims, BasedAuthDefaults.AuthenticationScheme); var claimsIdentity = new ClaimsIdentity(claims, BasedAuthDefaults.AuthenticationScheme);
var authState = new AuthenticationState(new ClaimsPrincipal(claimsIdentity)); var authState = new AuthenticationState(new ClaimsPrincipal(claimsIdentity));
_dataCache.CacheSessionState(authStateModel, authState); _dataCache.CacheSessionState(authStateModel, authState);