mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-01-18 10:04:20 +01:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
e62bdfeeae
13
DotBased.ASP.Auth/AuthenticationService.cs
Normal file
13
DotBased.ASP.Auth/AuthenticationService.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
namespace DotBased.ASP.Auth.Services;
|
||||||
|
|
||||||
|
public class AuthenticationService
|
||||||
|
{
|
||||||
|
public AuthenticationService()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* - Login
|
||||||
|
* - Logout
|
||||||
|
* - Register
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,4 +47,19 @@ public class BasedAuthConfiguration
|
||||||
public void SetSessionStateProviderType<TSessionStateProviderType>()
|
public void SetSessionStateProviderType<TSessionStateProviderType>()
|
||||||
where TSessionStateProviderType : ISessionStateProvider =>
|
where TSessionStateProviderType : ISessionStateProvider =>
|
||||||
SessionStateProviderType = typeof(TSessionStateProviderType);
|
SessionStateProviderType = typeof(TSessionStateProviderType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BasedPasswordOptions
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BasedUserOptions
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BasedLockoutOptions
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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!");
|
||||||
|
|
11
DotBased.ASP.Auth/Models/Configuration/AuthConfiguration.cs
Normal file
11
DotBased.ASP.Auth/Models/Configuration/AuthConfiguration.cs
Normal 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();
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace DotBased.ASP.Auth.Models.Configuration;
|
||||||
|
|
||||||
|
public class CacheConfiguration
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace DotBased.ASP.Auth.Models.Configuration;
|
||||||
|
|
||||||
|
public class LockoutConfiguration
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace DotBased.ASP.Auth.Models.Configuration;
|
||||||
|
|
||||||
|
public class PasswordConfiguration
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace DotBased.ASP.Auth.Models.Configuration;
|
||||||
|
|
||||||
|
public class ProviderConfiguration
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace DotBased.ASP.Auth.Models.Configuration;
|
||||||
|
|
||||||
|
public class RepositoryConfiguration
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace DotBased.ASP.Auth.Models.Configuration;
|
||||||
|
|
||||||
|
public class UserConfiguration
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
9
DotBased.ASP.Auth/SecurityManager.cs
Normal file
9
DotBased.ASP.Auth/SecurityManager.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
namespace DotBased.ASP.Auth.Managers;
|
||||||
|
|
||||||
|
public class SecurityManager
|
||||||
|
{
|
||||||
|
public SecurityManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
Loading…
Reference in New Issue
Block a user