mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-01-18 10:04:20 +01:00
[ADD] Base Authority initial commit
This commit is contained in:
parent
21675300bb
commit
2361e12847
|
@ -30,7 +30,7 @@ public static class DotBasedAuthDependencyInjection
|
|||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultScheme = BasedAuthDefaults.AuthenticationScheme;
|
||||
});/*.AddScheme<BasedAuthenticationHandlerOptions, BasedAuthenticationHandler>(BasedAuthDefaults.AuthenticationScheme, null);*/
|
||||
});
|
||||
services.AddAuthorization();
|
||||
services.AddCascadingAuthenticationState();
|
||||
return services;
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DotBased.AspNet.Auth;
|
||||
|
||||
public static class BasedAuthExtensions
|
||||
{
|
||||
public static IServiceCollection AddBasedAuthentication(this IServiceCollection services)
|
||||
{
|
||||
return services;
|
||||
}
|
||||
}
|
10
DotBased.AspNet.Authority/Attributes/ProtectAttribute.cs
Normal file
10
DotBased.AspNet.Authority/Attributes/ProtectAttribute.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace DotBased.AspNet.Authority.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the property should be protected.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ProtectAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
13
DotBased.AspNet.Authority/AuthorityBuilder.cs
Normal file
13
DotBased.AspNet.Authority/AuthorityBuilder.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DotBased.AspNet.Authority;
|
||||
|
||||
public class AuthorityBuilder
|
||||
{
|
||||
public AuthorityBuilder(IServiceCollection services)
|
||||
{
|
||||
Services = services;
|
||||
}
|
||||
|
||||
public IServiceCollection Services { get; }
|
||||
}
|
11
DotBased.AspNet.Authority/AuthorityDefaults.cs
Normal file
11
DotBased.AspNet.Authority/AuthorityDefaults.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace DotBased.AspNet.Authority;
|
||||
|
||||
public static class AuthorityDefaults
|
||||
{
|
||||
public static class Scheme
|
||||
{
|
||||
public const string AuthenticationScheme = "Authority.Scheme.Authentication";
|
||||
public const string ExternalScheme = "Authority.Scheme.External";
|
||||
}
|
||||
|
||||
}
|
17
DotBased.AspNet.Authority/AuthorityProviderExtensions.cs
Normal file
17
DotBased.AspNet.Authority/AuthorityProviderExtensions.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using DotBased.AspNet.Authority.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DotBased.AspNet.Authority;
|
||||
|
||||
public static class AuthorityProviderExtensions
|
||||
{
|
||||
public static AuthorityBuilder AddAuthorityProvider<TModel>(this IServiceCollection services) where TModel : class
|
||||
{
|
||||
return new AuthorityBuilder(services);
|
||||
}
|
||||
|
||||
public static AuthorityBuilder AddAuthorityStore<TStore>(this AuthorityBuilder authorityBuilder) where TStore : IAuthorityRepository
|
||||
{
|
||||
return authorityBuilder;
|
||||
}
|
||||
}
|
|
@ -7,8 +7,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Repositories\" />
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions">
|
||||
<HintPath>..\..\..\.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\8.0.2\lib\net8.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -16,16 +17,9 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore.Authentication">
|
||||
<HintPath>..\..\..\..\..\usr\lib64\dotnet\shared\Microsoft.AspNetCore.App\8.0.11\Microsoft.AspNetCore.Authentication.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions">
|
||||
<HintPath>..\..\..\.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\8.0.2\lib\net8.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.11" />
|
||||
<Folder Include="Authentication\" />
|
||||
<Folder Include="Models\Security\" />
|
||||
<Folder Include="Repositories\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,6 @@
|
|||
namespace DotBased.AspNet.Authority.Interfaces;
|
||||
|
||||
public interface IAttributeRepository
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace DotBased.AspNet.Authority.Interfaces;
|
||||
|
||||
public interface IAuthorityRepository
|
||||
{
|
||||
|
||||
}
|
6
DotBased.AspNet.Authority/Interfaces/IRoleRepository.cs
Normal file
6
DotBased.AspNet.Authority/Interfaces/IRoleRepository.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace DotBased.AspNet.Authority.Interfaces;
|
||||
|
||||
public interface IRoleRepository
|
||||
{
|
||||
|
||||
}
|
6
DotBased.AspNet.Authority/Interfaces/IUserRepository.cs
Normal file
6
DotBased.AspNet.Authority/Interfaces/IUserRepository.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace DotBased.AspNet.Authority.Interfaces;
|
||||
|
||||
public interface IUserRepository
|
||||
{
|
||||
|
||||
}
|
10
DotBased.AspNet.Authority/Models/Authority/AuthorityUser.cs
Normal file
10
DotBased.AspNet.Authority/Models/Authority/AuthorityUser.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace DotBased.AspNet.Authority.Models.Authority;
|
||||
|
||||
public class AuthorityUser : AuthorityUserBase<Guid>
|
||||
{
|
||||
public AuthorityUser()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
CreatedDate = DateTime.Now;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
using DotBased.AspNet.Authority.Attributes;
|
||||
|
||||
namespace DotBased.AspNet.Authority.Models.Authority;
|
||||
|
||||
public abstract class AuthorityUserBase<TKey> where TKey : IEquatable<TKey>
|
||||
{
|
||||
public TKey Id { get; set; }
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public bool Locked { get; set; }
|
||||
|
||||
public string UserName { get; set; }
|
||||
|
||||
public string PasswordHash { get; set; }
|
||||
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
|
||||
|
||||
[Protect]
|
||||
public string EmailAddress { get; set; }
|
||||
|
||||
public bool EmailConfirmed { get; set; }
|
||||
|
||||
[Protect]
|
||||
public string PhoneNumber { get; set; }
|
||||
|
||||
public bool PhoneNumberConfirmed { get; set; }
|
||||
|
||||
}
|
6
DotBased.AspNet.Authority/Services/AuthorityService.cs
Normal file
6
DotBased.AspNet.Authority/Services/AuthorityService.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace DotBased.AspNet.Authority.Services;
|
||||
|
||||
public class AuthorityService
|
||||
{
|
||||
|
||||
}
|
12
DotBased.sln
12
DotBased.sln
|
@ -20,7 +20,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor.Wasm", "Blazor.Wasm\
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AspNet", "AspNet", "{624E7B11-8A18-46E5-AB1F-6AF6097F9D4D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased.AspNet.Auth", "DotBased.AspNet.Auth\DotBased.AspNet.Auth.csproj", "{6F407D81-DFAC-4936-ACDD-D75E9FDE2E7B}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased.AspNet.Authority", "DotBased.AspNet.Authority\DotBased.AspNet.Authority.csproj", "{A3ADC9AF-39B7-4EC4-8022-946118A8C322}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -56,10 +56,10 @@ Global
|
|||
{AC8343A5-7953-4E1D-A926-406BE4D7E819}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AC8343A5-7953-4E1D-A926-406BE4D7E819}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AC8343A5-7953-4E1D-A926-406BE4D7E819}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6F407D81-DFAC-4936-ACDD-D75E9FDE2E7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6F407D81-DFAC-4936-ACDD-D75E9FDE2E7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6F407D81-DFAC-4936-ACDD-D75E9FDE2E7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6F407D81-DFAC-4936-ACDD-D75E9FDE2E7B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A3ADC9AF-39B7-4EC4-8022-946118A8C322}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A3ADC9AF-39B7-4EC4-8022-946118A8C322}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A3ADC9AF-39B7-4EC4-8022-946118A8C322}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A3ADC9AF-39B7-4EC4-8022-946118A8C322}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{EBBDAF9A-BFC7-4BDC-8C51-0501B59A1DDC} = {2156FB93-C252-4B33-8A0C-73C82FABB163}
|
||||
|
@ -68,6 +68,6 @@ Global
|
|||
{BADA4BAF-142B-47A8-95FC-B25E1D3D0020} = {DBDB4538-85D4-45AC-9E0A-A684467AEABA}
|
||||
{AC8343A5-7953-4E1D-A926-406BE4D7E819} = {DBDB4538-85D4-45AC-9E0A-A684467AEABA}
|
||||
{624E7B11-8A18-46E5-AB1F-6AF6097F9D4D} = {2156FB93-C252-4B33-8A0C-73C82FABB163}
|
||||
{6F407D81-DFAC-4936-ACDD-D75E9FDE2E7B} = {624E7B11-8A18-46E5-AB1F-6AF6097F9D4D}
|
||||
{A3ADC9AF-39B7-4EC4-8022-946118A8C322} = {624E7B11-8A18-46E5-AB1F-6AF6097F9D4D}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -2,6 +2,7 @@ using DotBased.Logging;
|
|||
using DotBased.Logging.MEL;
|
||||
using DotBased.Logging.Serilog;
|
||||
using Serilog;
|
||||
using TestWebApi;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
@ -18,6 +19,12 @@ LogService.AddLogAdapter(new BasedSerilogAdapter(serilogLogger));
|
|||
builder.Logging.ClearProviders();
|
||||
builder.Logging.AddDotBasedLoggerProvider(LogService.Options);
|
||||
|
||||
/*builder.Services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultScheme = BasedAuthenticationDefaults.BasedAuthenticationScheme;
|
||||
options.DefaultChallengeScheme = BasedAuthenticationDefaults.BasedAuthenticationScheme;
|
||||
}).AddCookie();*/
|
||||
|
||||
// Add services to the container.
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
@ -25,6 +32,8 @@ builder.Services.AddSwaggerGen();
|
|||
|
||||
var app = builder.Build();
|
||||
|
||||
await SeedAuthorityData.InitializeData(app.Services);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
|
|
9
TestWebApi/SeedAuthorityData.cs
Normal file
9
TestWebApi/SeedAuthorityData.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace TestWebApi;
|
||||
|
||||
public class SeedAuthorityData
|
||||
{
|
||||
public static async Task InitializeData(IServiceProvider serviceProvider)
|
||||
{
|
||||
// Get the needed services and create users, roles, attributes. etc.
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DotBased.AspNet.Authority\DotBased.AspNet.Authority.csproj" />
|
||||
<ProjectReference Include="..\DotBased.Logging.MEL\DotBased.Logging.MEL.csproj" />
|
||||
<ProjectReference Include="..\DotBased.Logging.Serilog\DotBased.Logging.Serilog.csproj" />
|
||||
<ProjectReference Include="..\DotBased\DotBased.csproj" />
|
||||
|
|
Loading…
Reference in New Issue
Block a user