mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-06-08 01:16:18 +02:00
Compare commits
No commits in common. "05b95c60502bfe419139b3bdce563af2998e3743" and "e22b7790dde10299efa7418af00ffac5e459df49" have entirely different histories.
05b95c6050
...
e22b7790dd
|
@ -6,18 +6,18 @@ public static class AuthorityDefaults
|
||||||
{
|
{
|
||||||
public static class Authority
|
public static class Authority
|
||||||
{
|
{
|
||||||
public const string AuthenticationScheme = "AuthorityLogin";
|
public const string AuthenticationScheme = "Authority.Scheme.Password";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Cookie
|
public static class Cookie
|
||||||
{
|
{
|
||||||
public const string AuthenticationScheme = "AuthorityCookie";
|
public const string Default = "Authority.Scheme.Cookie";
|
||||||
public const string CookieName = "AuthorityAuth";
|
public const string CookieName = "AuthorityAuth";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Token
|
public static class Token
|
||||||
{
|
{
|
||||||
public const string AuthenticationScheme = "AuthorityToken";
|
public const string Default = "Authority.Scheme.Token";
|
||||||
public const string TokenName = "AuthorityAuthToken";
|
public const string TokenName = "AuthorityAuthToken";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using DotBased.AspNet.Authority.Crypto;
|
using DotBased.AspNet.Authority.Crypto;
|
||||||
using DotBased.AspNet.Authority.Handlers;
|
|
||||||
using DotBased.AspNet.Authority.Managers;
|
using DotBased.AspNet.Authority.Managers;
|
||||||
using DotBased.AspNet.Authority.Models.Options;
|
using DotBased.AspNet.Authority.Models.Options;
|
||||||
using DotBased.AspNet.Authority.Models.Options.Auth;
|
using DotBased.AspNet.Authority.Models.Options.Auth;
|
||||||
|
@ -34,41 +33,29 @@ public static class AuthorityProviderExtensions
|
||||||
return new AuthorityBuilder(services);
|
return new AuthorityBuilder(services);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AuthenticationBuilder AddAuthorityAuth(this AuthorityBuilder builder) => AddAuthorityAuth(builder, _ => { });
|
||||||
|
|
||||||
public static AuthenticationBuilder AddAuthorityAuth(this AuthorityBuilder builder, Action<AuthorityAuthenticationOptions> configureOptions)
|
public static AuthenticationBuilder AddAuthorityAuth(this AuthorityBuilder builder, Action<AuthorityAuthenticationOptions> configureOptions)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(configureOptions);
|
ArgumentNullException.ThrowIfNull(configureOptions);
|
||||||
builder.Services.Configure(configureOptions);
|
builder.Services.Configure(configureOptions);
|
||||||
|
|
||||||
builder.Services.AddScoped<IAuthenticationService, AuthorityAuthenticationService>();
|
builder.Services.AddScoped<IAuthenticationService, AuthorityAuthenticationService>();
|
||||||
|
//TODO: Register authority default authentication handler
|
||||||
|
|
||||||
var authorityOptions = new AuthorityAuthenticationOptions();
|
var authBuilder = builder.Services.AddAuthentication();
|
||||||
configureOptions.Invoke(authorityOptions);
|
|
||||||
|
|
||||||
var authBuilder = builder.Services.AddAuthentication(options =>
|
|
||||||
{
|
|
||||||
options.DefaultScheme = authorityOptions.DefaultScheme;
|
|
||||||
options.DefaultAuthenticateScheme = authorityOptions.DefaultAuthenticateScheme;
|
|
||||||
options.DefaultChallengeScheme = authorityOptions.DefaultChallengeScheme;
|
|
||||||
options.DefaultSignInScheme = authorityOptions.DefaultSignInScheme;
|
|
||||||
options.DefaultSignOutScheme = authorityOptions.DefaultSignOutScheme;
|
|
||||||
options.DefaultForbidScheme = authorityOptions.DefaultForbidScheme;
|
|
||||||
});
|
|
||||||
return authBuilder;
|
return authBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthenticationBuilder AddAuthorityLoginScheme(this AuthenticationBuilder builder, string scheme) =>
|
public static AuthenticationBuilder AddAuthorityLoginScheme(this AuthenticationBuilder builder, string scheme = AuthorityDefaults.Scheme.Authority.AuthenticationScheme)
|
||||||
AddAuthorityLoginScheme(builder, scheme, _ => { });
|
|
||||||
public static AuthenticationBuilder AddAuthorityLoginScheme(this AuthenticationBuilder builder,
|
|
||||||
string scheme,
|
|
||||||
Action<AuthorityLoginOptions> configureOptions)
|
|
||||||
{
|
{
|
||||||
builder.AddScheme<AuthorityLoginOptions, AuthorityLoginAuthenticationHandler>(scheme, scheme, configureOptions);
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthenticationBuilder AddAuthorityCookie(this AuthenticationBuilder builder, string scheme)
|
public static AuthenticationBuilder AddAuthorityCookie(this AuthenticationBuilder builder, string scheme = AuthorityDefaults.Scheme.Cookie.Default)
|
||||||
{
|
{
|
||||||
builder.AddCookie(scheme, options =>
|
builder.AddCookie(options =>
|
||||||
{
|
{
|
||||||
options.Cookie.Name = AuthorityDefaults.Scheme.Cookie.CookieName;
|
options.Cookie.Name = AuthorityDefaults.Scheme.Cookie.CookieName;
|
||||||
options.Cookie.Path = AuthorityDefaults.Paths.Default;
|
options.Cookie.Path = AuthorityDefaults.Paths.Default;
|
||||||
|
@ -84,7 +71,7 @@ public static class AuthorityProviderExtensions
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthenticationBuilder AddAuthorityToken(this AuthenticationBuilder builder, string scheme)
|
public static AuthenticationBuilder AddAuthorityToken(this AuthenticationBuilder builder, string scheme = AuthorityDefaults.Scheme.Token.Default)
|
||||||
{
|
{
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
|
|
|
@ -1,35 +1,10 @@
|
||||||
using System.Text.Json;
|
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Components;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace DotBased.AspNet.Authority.Controllers;
|
namespace DotBased.AspNet.Authority.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Microsoft.AspNetCore.Mvc.Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class AuthorityController : ControllerBase
|
public class AuthorityController : ControllerBase
|
||||||
{
|
{
|
||||||
[Inject]
|
|
||||||
public IAuthenticationService AuthenticationService { get; set; }
|
|
||||||
|
|
||||||
[HttpGet("auth/login")]
|
|
||||||
[AllowAnonymous]
|
|
||||||
public async Task<ActionResult> LoginFromSchemeAsync([FromQuery(Name = "s")] string? scheme)
|
|
||||||
{
|
|
||||||
var authResult = await HttpContext.AuthenticateAsync();
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("auth/logout")]
|
|
||||||
public async Task<ActionResult> LogoutAsync()
|
|
||||||
{
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("info")]
|
|
||||||
public async Task<ActionResult<JsonDocument>> GetAuthorityInfoAsync()
|
|
||||||
{
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -7,7 +7,9 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
<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>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -20,7 +22,10 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.3.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.3.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.3.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace DotBased.AspNet.Authority.Handlers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles authentication for Authority logins.
|
||||||
|
/// </summary>
|
||||||
|
public class AuthorityAuthenticationHandler : IAuthenticationSignInHandler
|
||||||
|
{
|
||||||
|
public Task InitializeAsync(AuthenticationScheme scheme, HttpContext context)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<AuthenticateResult> AuthenticateAsync()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task ChallengeAsync(AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task ForbidAsync(AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SignOutAsync(AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,34 +0,0 @@
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Text.Encodings.Web;
|
|
||||||
using DotBased.AspNet.Authority.Managers;
|
|
||||||
using DotBased.AspNet.Authority.Models.Options.Auth;
|
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
|
|
||||||
namespace DotBased.AspNet.Authority.Handlers;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles authentication for Authority logins.
|
|
||||||
/// </summary>
|
|
||||||
public class AuthorityLoginAuthenticationHandler(IOptionsMonitor<AuthorityLoginOptions> options,
|
|
||||||
ILoggerFactory logger,
|
|
||||||
UrlEncoder encoder,
|
|
||||||
ISystemClock clock,
|
|
||||||
AuthorityManager manager) : SignInAuthenticationHandler<AuthorityLoginOptions>(options, logger, encoder, clock)
|
|
||||||
{
|
|
||||||
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Task HandleSignOutAsync(AuthenticationProperties properties)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Task HandleSignInAsync(ClaimsPrincipal user, AuthenticationProperties properties)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,16 +10,13 @@ public class AuthorityAuthenticationOptions
|
||||||
public string DefaultForbidScheme { get; set; } = string.Empty;
|
public string DefaultForbidScheme { get; set; } = string.Empty;
|
||||||
public string DefaultSignInScheme { get; set; } = string.Empty;
|
public string DefaultSignInScheme { get; set; } = string.Empty;
|
||||||
public string DefaultSignOutScheme { get; set; } = string.Empty;
|
public string DefaultSignOutScheme { get; set; } = string.Empty;
|
||||||
/// <summary>
|
public List<SchemeInfo> SchemeMap { get; set; } = [];
|
||||||
/// List of schemes that the Authority application will support to authenticate against.
|
|
||||||
/// </summary>
|
|
||||||
public List<SchemeInfo> SchemeInfoMap { get; set; } = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SchemeInfo
|
public class SchemeInfo
|
||||||
{
|
{
|
||||||
public string Scheme { get; set; } = string.Empty;
|
public string Scheme { get; set; } = string.Empty;
|
||||||
public string Description { get; set; } = string.Empty;
|
public string Identifier { get; set; } = string.Empty;
|
||||||
public SchemeType Type { get; set; }
|
public SchemeType Type { get; set; }
|
||||||
public string AuthenticationType { get; set; } = string.Empty;
|
public string AuthenticationType { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
|
|
||||||
namespace DotBased.AspNet.Authority.Models.Options.Auth;
|
|
||||||
|
|
||||||
public class AuthorityLoginOptions : AuthenticationSchemeOptions
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,20 +1,101 @@
|
||||||
|
using System.Security.Claims;
|
||||||
using DotBased.AspNet.Authority.Models.Options.Auth;
|
using DotBased.AspNet.Authority.Models.Options.Auth;
|
||||||
using DotBased.Logging;
|
using DotBased.Logging;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace DotBased.AspNet.Authority.Services;
|
namespace DotBased.AspNet.Authority.Services;
|
||||||
|
|
||||||
public class AuthorityAuthenticationService(
|
public class AuthorityAuthenticationService(
|
||||||
IAuthenticationSchemeProvider schemes,
|
|
||||||
IAuthenticationHandlerProvider handlers,
|
IAuthenticationHandlerProvider handlers,
|
||||||
IClaimsTransformation transform,
|
IClaimsTransformation transform,
|
||||||
IOptions<AuthenticationOptions> options,
|
IOptions<AuthorityAuthenticationOptions> options) : IAuthenticationService
|
||||||
IOptions<AuthorityAuthenticationOptions> authorityOptions) : AuthenticationService(schemes, handlers, transform, options)
|
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger = LogService.RegisterLogger(typeof(AuthorityAuthenticationService));
|
private readonly ILogger _logger = LogService.RegisterLogger(typeof(AuthorityAuthenticationService));
|
||||||
private readonly AuthorityAuthenticationOptions _options = authorityOptions.Value;
|
private readonly AuthorityAuthenticationOptions _options = options.Value;
|
||||||
|
|
||||||
public IReadOnlyCollection<SchemeInfo> GetSchemeInfos(SchemeType schemeType) => _options.SchemeInfoMap.Where(s => s.Type == schemeType).ToList();
|
public async Task<AuthenticateResult> AuthenticateAsync(HttpContext context, string scheme)
|
||||||
public IReadOnlyCollection<SchemeInfo> GetAllSchemeInfos() => _options.SchemeInfoMap;
|
{
|
||||||
|
_logger.Debug("Authenticate with scheme: {Scheme}", scheme);
|
||||||
|
|
||||||
|
var authenticationHandler = await GetAuthenticationHandler(context, scheme, _options.DefaultAuthenticateScheme);
|
||||||
|
var authResult = await authenticationHandler.AuthenticateAsync();
|
||||||
|
|
||||||
|
return authResult is { Succeeded: true }
|
||||||
|
? AuthenticateResult.Success(
|
||||||
|
new AuthenticationTicket(await transform.TransformAsync(authResult.Principal), authResult.Properties, authResult.Ticket.AuthenticationScheme)) :
|
||||||
|
AuthenticateResult.Fail("Failed to authenticate");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ChallengeAsync(HttpContext context, string scheme, AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
_logger.Debug("Challenging with scheme: {Scheme}", scheme);
|
||||||
|
|
||||||
|
var authenticationHandler = await GetAuthenticationHandler(context, scheme, _options.DefaultChallengeScheme);
|
||||||
|
await authenticationHandler.ChallengeAsync(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ForbidAsync(HttpContext context, string scheme, AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
_logger.Debug("Forbid with scheme: {Scheme}", scheme);
|
||||||
|
|
||||||
|
var authenticationHandler = await GetAuthenticationHandler(context, scheme, _options.DefaultForbidScheme);
|
||||||
|
await authenticationHandler.ForbidAsync(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SignInAsync(HttpContext context, string scheme, ClaimsPrincipal principal, AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
_logger.Debug("SignIn with scheme: {Scheme}", scheme);
|
||||||
|
|
||||||
|
var authenticationHandler = await GetAuthenticationHandler(context, scheme, _options.DefaultSignInScheme);
|
||||||
|
if (authenticationHandler is not IAuthenticationSignInHandler signInHandler)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Authentication handler is not a IAuthenticationSignInHandler.");
|
||||||
|
}
|
||||||
|
await signInHandler.SignInAsync(principal, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SignOutAsync(HttpContext context, string scheme, AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
_logger.Debug("SignOut with scheme: {Scheme}", scheme);
|
||||||
|
|
||||||
|
var authenticationHandler = await GetAuthenticationHandler(context, scheme, _options.DefaultSignOutScheme);
|
||||||
|
if (authenticationHandler is not IAuthenticationSignOutHandler signOutHandler)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Authentication handler is not a IAuthenticationSignOutHandler.");
|
||||||
|
}
|
||||||
|
await signOutHandler.SignOutAsync(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public async Task ValidateLoginAsync()
|
||||||
|
{
|
||||||
|
//TODO: Check if user is logged in from external identity provider, if user not exists in authority db create user.
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
private async Task<IAuthenticationHandler> GetAuthenticationHandler(HttpContext context, string scheme, string defaultScheme)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(scheme))
|
||||||
|
{
|
||||||
|
scheme = defaultScheme;
|
||||||
|
if (string.IsNullOrWhiteSpace(scheme))
|
||||||
|
{
|
||||||
|
scheme = _options.DefaultScheme;
|
||||||
|
if (string.IsNullOrWhiteSpace(scheme))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Failed to get default scheme. No scheme specified.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var authenticationHandler = await handlers.GetHandlerAsync(context, scheme);
|
||||||
|
if (authenticationHandler == null)
|
||||||
|
{
|
||||||
|
_logger.Warning("Failed to load handler for scheme: {Scheme}", scheme);
|
||||||
|
throw new InvalidOperationException($"No authentication handlers registered to the scheme '{scheme}'");
|
||||||
|
}
|
||||||
|
|
||||||
|
return authenticationHandler;
|
||||||
|
}
|
||||||
}
|
}
|
12
DotBased.Data/DotBased.Data.csproj
Normal file
12
DotBased.Data/DotBased.Data.csproj
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DotBased\DotBased.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AspNet", "AspNet", "{624E7B
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased.AspNet.Authority", "DotBased.AspNet.Authority\DotBased.AspNet.Authority.csproj", "{A3ADC9AF-39B7-4EC4-8022-946118A8C322}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased.AspNet.Authority", "DotBased.AspNet.Authority\DotBased.AspNet.Authority.csproj", "{A3ADC9AF-39B7-4EC4-8022-946118A8C322}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased.Data", "DotBased.Data\DotBased.Data.csproj", "{2DF9FEEF-5A60-4B41-9B5F-F883DCE33EF4}"
|
||||||
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased.AspNet.Authority.EFCore", "DotBased.AspNet.Authority.EFCore\DotBased.AspNet.Authority.EFCore.csproj", "{F1F3F60B-911F-4036-8A2B-CEC18A8F59DD}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotBased.AspNet.Authority.EFCore", "DotBased.AspNet.Authority.EFCore\DotBased.AspNet.Authority.EFCore.csproj", "{F1F3F60B-911F-4036-8A2B-CEC18A8F59DD}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
@ -62,6 +64,10 @@ Global
|
||||||
{A3ADC9AF-39B7-4EC4-8022-946118A8C322}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
|
||||||
{A3ADC9AF-39B7-4EC4-8022-946118A8C322}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A3ADC9AF-39B7-4EC4-8022-946118A8C322}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{2DF9FEEF-5A60-4B41-9B5F-F883DCE33EF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{2DF9FEEF-5A60-4B41-9B5F-F883DCE33EF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{2DF9FEEF-5A60-4B41-9B5F-F883DCE33EF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{2DF9FEEF-5A60-4B41-9B5F-F883DCE33EF4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{F1F3F60B-911F-4036-8A2B-CEC18A8F59DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{F1F3F60B-911F-4036-8A2B-CEC18A8F59DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{F1F3F60B-911F-4036-8A2B-CEC18A8F59DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F1F3F60B-911F-4036-8A2B-CEC18A8F59DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F1F3F60B-911F-4036-8A2B-CEC18A8F59DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{F1F3F60B-911F-4036-8A2B-CEC18A8F59DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
@ -75,6 +81,7 @@ Global
|
||||||
{AC8343A5-7953-4E1D-A926-406BE4D7E819} = {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}
|
{624E7B11-8A18-46E5-AB1F-6AF6097F9D4D} = {2156FB93-C252-4B33-8A0C-73C82FABB163}
|
||||||
{A3ADC9AF-39B7-4EC4-8022-946118A8C322} = {624E7B11-8A18-46E5-AB1F-6AF6097F9D4D}
|
{A3ADC9AF-39B7-4EC4-8022-946118A8C322} = {624E7B11-8A18-46E5-AB1F-6AF6097F9D4D}
|
||||||
|
{2DF9FEEF-5A60-4B41-9B5F-F883DCE33EF4} = {2156FB93-C252-4B33-8A0C-73C82FABB163}
|
||||||
{F1F3F60B-911F-4036-8A2B-CEC18A8F59DD} = {624E7B11-8A18-46E5-AB1F-6AF6097F9D4D}
|
{F1F3F60B-911F-4036-8A2B-CEC18A8F59DD} = {624E7B11-8A18-46E5-AB1F-6AF6097F9D4D}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
@ -27,9 +27,4 @@ public class WeatherController : ControllerBase
|
||||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||||
return forecast;
|
return forecast;
|
||||||
}
|
}
|
||||||
|
|
||||||
public record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
|
||||||
{
|
|
||||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -25,49 +25,45 @@ builder.Logging.AddDotBasedLoggerProvider(LogService.Options);
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
builder.Services.AddAuthority()
|
builder.Services.AddAuthority().AddAuthorityContext(options =>
|
||||||
.AddAuthorityContext(options =>
|
|
||||||
{
|
{
|
||||||
options.UseSqlite("Data Source=dev-authority.db", c => c.MigrationsAssembly("TestWebApi"));
|
options.UseSqlite("Data Source=dev-authority.db", c => c.MigrationsAssembly("TestWebApi"));
|
||||||
})
|
}).AddAuthorityAuth(options =>
|
||||||
.MapAuthorityEndpoints()
|
|
||||||
.AddAuthorityAuth(options =>
|
|
||||||
{
|
{
|
||||||
options.DefaultScheme = AuthorityDefaults.Scheme.Cookie.AuthenticationScheme;
|
options.DefaultScheme = AuthorityDefaults.Scheme.Authority.AuthenticationScheme;
|
||||||
options.DefaultSignInScheme = AuthorityDefaults.Scheme.Authority.AuthenticationScheme;
|
//TODO: Auto detect auth and session store schemes?
|
||||||
options.DefaultChallengeScheme = AuthorityDefaults.Scheme.Authority.AuthenticationScheme;
|
options.SchemeMap = [
|
||||||
options.SchemeInfoMap = [
|
|
||||||
new SchemeInfo
|
new SchemeInfo
|
||||||
{
|
{
|
||||||
Scheme = AuthorityDefaults.Scheme.Authority.AuthenticationScheme,
|
Scheme = AuthorityDefaults.Scheme.Authority.AuthenticationScheme,
|
||||||
Description = "Authority password login",
|
Identifier = "Authority password login",
|
||||||
Type = SchemeType.Authentication,
|
Type = SchemeType.Authentication,
|
||||||
AuthenticationType = "Password"
|
AuthenticationType = "Password"
|
||||||
},
|
},
|
||||||
/*new SchemeInfo
|
new SchemeInfo
|
||||||
{
|
{
|
||||||
Scheme = "OIDC",
|
Scheme = "OIDC",
|
||||||
Description = "Authentik OIDC login",
|
Identifier = "Authentik OIDC login",
|
||||||
Type = SchemeType.Authentication,
|
Type = SchemeType.Authentication,
|
||||||
AuthenticationType = "OpenIdConnect"
|
AuthenticationType = "OpenIdConnect"
|
||||||
},*/
|
},
|
||||||
new SchemeInfo
|
new SchemeInfo
|
||||||
{
|
{
|
||||||
Scheme = AuthorityDefaults.Scheme.Cookie.AuthenticationScheme,
|
Scheme = AuthorityDefaults.Scheme.Cookie.Default,
|
||||||
Description = "Cookie session",
|
Identifier = "Cookie session",
|
||||||
Type = SchemeType.SessionStore
|
Type = SchemeType.SessionStore
|
||||||
}/*,
|
},
|
||||||
new SchemeInfo
|
new SchemeInfo
|
||||||
{
|
{
|
||||||
Scheme = AuthorityDefaults.Scheme.Token.AuthenticationScheme,
|
Scheme = AuthorityDefaults.Scheme.Token.Default,
|
||||||
Description = "Session token",
|
Identifier = "Session token",
|
||||||
Type = SchemeType.SessionStore
|
Type = SchemeType.SessionStore
|
||||||
}*/
|
}
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
.AddAuthorityLoginScheme(AuthorityDefaults.Scheme.Authority.AuthenticationScheme)
|
.AddAuthorityLoginScheme()
|
||||||
.AddAuthorityCookie(AuthorityDefaults.Scheme.Cookie.AuthenticationScheme)
|
.AddAuthorityCookie()
|
||||||
.AddAuthorityToken(AuthorityDefaults.Scheme.Token.AuthenticationScheme);
|
.AddAuthorityToken();
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
@ -101,3 +97,8 @@ ILogger SetupSerilog()
|
||||||
.WriteTo.Console(outputTemplate: BasedSerilog.OutputTemplate);
|
.WriteTo.Console(outputTemplate: BasedSerilog.OutputTemplate);
|
||||||
return logConfig.CreateLogger();
|
return logConfig.CreateLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
||||||
|
{
|
||||||
|
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user