From 46dbd8c6f54b9762d42262fb7051cae88694a575 Mon Sep 17 00:00:00 2001 From: max Date: Mon, 5 May 2025 16:00:18 +0200 Subject: [PATCH] [WIP] --- .../Controllers/AuthorityController.cs | 12 ++++---- .../AuthorityLoginAuthenticationHandler.cs | 7 ++--- .../AuthorityAuthenticationService.cs | 28 +++++++++++++++++++ TestWebApi/Program.cs | 2 +- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/DotBased.AspNet.Authority/Controllers/AuthorityController.cs b/DotBased.AspNet.Authority/Controllers/AuthorityController.cs index 5fc1d63..a83ee86 100644 --- a/DotBased.AspNet.Authority/Controllers/AuthorityController.cs +++ b/DotBased.AspNet.Authority/Controllers/AuthorityController.cs @@ -1,33 +1,33 @@ +using System.Security.Claims; using System.Text.Json; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Mvc; namespace DotBased.AspNet.Authority.Controllers; [ApiController] -[Microsoft.AspNetCore.Mvc.Route("[controller]")] +[Route("[controller]")] public class AuthorityController : ControllerBase { - [Inject] - public IAuthenticationService AuthenticationService { get; set; } - [HttpGet("auth/login")] [AllowAnonymous] public async Task LoginFromSchemeAsync([FromQuery(Name = "s")] string? scheme) { - var authResult = await HttpContext.AuthenticateAsync(); + var cPrincipal = new ClaimsPrincipal(); + await HttpContext.SignInAsync(cPrincipal); return Ok(); } [HttpGet("auth/logout")] public async Task LogoutAsync() { + await HttpContext.SignOutAsync(); return Ok(); } [HttpGet("info")] + [AllowAnonymous] public async Task> GetAuthorityInfoAsync() { return Ok(); diff --git a/DotBased.AspNet.Authority/Handlers/AuthorityLoginAuthenticationHandler.cs b/DotBased.AspNet.Authority/Handlers/AuthorityLoginAuthenticationHandler.cs index 1efd59d..4a6875a 100644 --- a/DotBased.AspNet.Authority/Handlers/AuthorityLoginAuthenticationHandler.cs +++ b/DotBased.AspNet.Authority/Handlers/AuthorityLoginAuthenticationHandler.cs @@ -14,20 +14,19 @@ namespace DotBased.AspNet.Authority.Handlers; public class AuthorityLoginAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, - ISystemClock clock, - AuthorityManager manager) : SignInAuthenticationHandler(options, logger, encoder, clock) + AuthorityManager manager) : SignInAuthenticationHandler(options, logger, encoder) { protected override Task HandleAuthenticateAsync() { throw new NotImplementedException(); } - protected override Task HandleSignOutAsync(AuthenticationProperties properties) + protected override Task HandleSignOutAsync(AuthenticationProperties? properties) { throw new NotImplementedException(); } - protected override Task HandleSignInAsync(ClaimsPrincipal user, AuthenticationProperties properties) + protected override Task HandleSignInAsync(ClaimsPrincipal user, AuthenticationProperties? properties) { throw new NotImplementedException(); } diff --git a/DotBased.AspNet.Authority/Services/AuthorityAuthenticationService.cs b/DotBased.AspNet.Authority/Services/AuthorityAuthenticationService.cs index e199439..53cf5ad 100644 --- a/DotBased.AspNet.Authority/Services/AuthorityAuthenticationService.cs +++ b/DotBased.AspNet.Authority/Services/AuthorityAuthenticationService.cs @@ -1,6 +1,8 @@ +using System.Security.Claims; using DotBased.AspNet.Authority.Models.Options.Auth; using DotBased.Logging; using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; namespace DotBased.AspNet.Authority.Services; @@ -17,4 +19,30 @@ public class AuthorityAuthenticationService( public IReadOnlyCollection GetSchemeInfos(SchemeType schemeType) => _options.SchemeInfoMap.Where(s => s.Type == schemeType).ToList(); public IReadOnlyCollection GetAllSchemeInfos() => _options.SchemeInfoMap; + + public override Task AuthenticateAsync(HttpContext context, string? scheme) + { + + return base.AuthenticateAsync(context, scheme); + } + + public override Task ChallengeAsync(HttpContext context, string? scheme, AuthenticationProperties? properties) + { + return base.ChallengeAsync(context, scheme, properties); + } + + public override Task SignInAsync(HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties) + { + return base.SignInAsync(context, scheme, principal, properties); + } + + public override Task SignOutAsync(HttpContext context, string? scheme, AuthenticationProperties? properties) + { + return base.SignOutAsync(context, scheme, properties); + } + + public override Task ForbidAsync(HttpContext context, string? scheme, AuthenticationProperties? properties) + { + return base.ForbidAsync(context, scheme, properties); + } } \ No newline at end of file diff --git a/TestWebApi/Program.cs b/TestWebApi/Program.cs index aa3c731..e5aa9c3 100755 --- a/TestWebApi/Program.cs +++ b/TestWebApi/Program.cs @@ -35,7 +35,7 @@ builder.Services.AddAuthority() { options.DefaultScheme = AuthorityDefaults.Scheme.Cookie.AuthenticationScheme; options.DefaultSignInScheme = AuthorityDefaults.Scheme.Authority.AuthenticationScheme; - options.DefaultChallengeScheme = AuthorityDefaults.Scheme.Authority.AuthenticationScheme; + options.DefaultSignOutScheme = AuthorityDefaults.Scheme.Authority.AuthenticationScheme; options.SchemeInfoMap = [ new SchemeInfo {