mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-06-08 01:16:18 +02:00
Compare commits
No commits in common. "b3763fb795158d8d57e9c638f6bb83035a6c5253" and "46dbd8c6f54b9762d42262fb7051cae88694a575" have entirely different histories.
b3763fb795
...
46dbd8c6f5
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Security.Claims;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
@ -7,13 +8,14 @@ namespace DotBased.AspNet.Authority.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class AuthorityController(IAuthenticationService authenticationService) : ControllerBase
|
public class AuthorityController : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet("auth/login")]
|
[HttpGet("auth/login")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<ActionResult> LoginFromSchemeAsync([FromQuery(Name = "s")] string? scheme, [FromQuery(Name = "ss")] string? sessionScheme)
|
public async Task<ActionResult> LoginFromSchemeAsync([FromQuery(Name = "s")] string? scheme)
|
||||||
{
|
{
|
||||||
await authenticationService.AuthenticateAsync(HttpContext, scheme);
|
var cPrincipal = new ClaimsPrincipal();
|
||||||
|
await HttpContext.SignInAsync(cPrincipal);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,20 @@ namespace DotBased.AspNet.Authority.Handlers;
|
||||||
public class AuthorityLoginAuthenticationHandler(IOptionsMonitor<AuthorityLoginOptions> options,
|
public class AuthorityLoginAuthenticationHandler(IOptionsMonitor<AuthorityLoginOptions> options,
|
||||||
ILoggerFactory logger,
|
ILoggerFactory logger,
|
||||||
UrlEncoder encoder,
|
UrlEncoder encoder,
|
||||||
AuthorityManager manager) : AuthenticationHandler<AuthorityLoginOptions>(options, logger, encoder)
|
AuthorityManager manager) : SignInAuthenticationHandler<AuthorityLoginOptions>(options, logger, encoder)
|
||||||
{
|
{
|
||||||
// Validate credentials
|
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||||
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
|
|
||||||
{
|
{
|
||||||
var ticket = new AuthenticationTicket(new ClaimsPrincipal(), Scheme.Name);
|
throw new NotImplementedException();
|
||||||
var result = AuthenticateResult.Success(ticket);
|
}
|
||||||
return result;
|
|
||||||
|
protected override Task HandleSignOutAsync(AuthenticationProperties? properties)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task HandleSignInAsync(ClaimsPrincipal user, AuthenticationProperties? properties)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,35 +20,27 @@ public class AuthorityAuthenticationService(
|
||||||
public IReadOnlyCollection<SchemeInfo> GetSchemeInfos(SchemeType schemeType) => _options.SchemeInfoMap.Where(s => s.Type == schemeType).ToList();
|
public IReadOnlyCollection<SchemeInfo> GetSchemeInfos(SchemeType schemeType) => _options.SchemeInfoMap.Where(s => s.Type == schemeType).ToList();
|
||||||
public IReadOnlyCollection<SchemeInfo> GetAllSchemeInfos() => _options.SchemeInfoMap;
|
public IReadOnlyCollection<SchemeInfo> GetAllSchemeInfos() => _options.SchemeInfoMap;
|
||||||
|
|
||||||
// Validate credentials
|
|
||||||
// Used internally by ASP.NET Core to determine if a user is authenticated. Can also be called manually to inspect authentication status.
|
|
||||||
public override Task<AuthenticateResult> AuthenticateAsync(HttpContext context, string? scheme)
|
public override Task<AuthenticateResult> AuthenticateAsync(HttpContext context, string? scheme)
|
||||||
{
|
{
|
||||||
|
|
||||||
return base.AuthenticateAsync(context, scheme);
|
return base.AuthenticateAsync(context, scheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger login
|
|
||||||
// Used when access to a resource requires authentication, but the user has not provided valid credentials.
|
|
||||||
public override Task ChallengeAsync(HttpContext context, string? scheme, AuthenticationProperties? properties)
|
public override Task ChallengeAsync(HttpContext context, string? scheme, AuthenticationProperties? properties)
|
||||||
{
|
{
|
||||||
return base.ChallengeAsync(context, scheme, properties);
|
return base.ChallengeAsync(context, scheme, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log user in, set cookie/token
|
|
||||||
// Called after successfully validating user credentials (e.g., after login form submission), to establish an authenticated session.
|
|
||||||
public override Task SignInAsync(HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties)
|
public override Task SignInAsync(HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties)
|
||||||
{
|
{
|
||||||
return base.SignInAsync(context, scheme, principal, properties);
|
return base.SignInAsync(context, scheme, principal, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log out user and end auth session, remove cookie/token
|
|
||||||
public override Task SignOutAsync(HttpContext context, string? scheme, AuthenticationProperties? properties)
|
public override Task SignOutAsync(HttpContext context, string? scheme, AuthenticationProperties? properties)
|
||||||
{
|
{
|
||||||
return base.SignOutAsync(context, scheme, properties);
|
return base.SignOutAsync(context, scheme, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deny access, return 403/return forbid page
|
|
||||||
// Used when a user is authenticated but lacks required roles/claims/permissions.
|
|
||||||
public override Task ForbidAsync(HttpContext context, string? scheme, AuthenticationProperties? properties)
|
public override Task ForbidAsync(HttpContext context, string? scheme, AuthenticationProperties? properties)
|
||||||
{
|
{
|
||||||
return base.ForbidAsync(context, scheme, properties);
|
return base.ForbidAsync(context, scheme, properties);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user