This commit is contained in:
max
2025-05-18 18:03:40 +02:00
parent b3763fb795
commit 217c55df00
8 changed files with 75 additions and 22 deletions

View File

@@ -1,4 +1,6 @@
using System.Text.Json;
using DotBased.AspNet.Authority.Models.Data.System;
using DotBased.AspNet.Authority.Services;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -9,7 +11,7 @@ namespace DotBased.AspNet.Authority.Controllers;
[Route("[controller]")]
public class AuthorityController(IAuthenticationService authenticationService) : ControllerBase
{
[HttpGet("auth/login")]
[HttpGet(AuthorityDefaults.Paths.Login)]
[AllowAnonymous]
public async Task<ActionResult> LoginFromSchemeAsync([FromQuery(Name = "s")] string? scheme, [FromQuery(Name = "ss")] string? sessionScheme)
{
@@ -17,17 +19,41 @@ public class AuthorityController(IAuthenticationService authenticationService) :
return Ok();
}
[HttpGet("auth/logout")]
[HttpGet(AuthorityDefaults.Paths.Challenge)]
[AllowAnonymous]
public IActionResult ChallengeLogin([FromQuery(Name = "s")] string? scheme, [FromQuery(Name = "returnUrl")] string returnUrl = "/")
{
return Challenge(scheme, returnUrl);
}
[HttpGet(AuthorityDefaults.Paths.Logout)]
public async Task<ActionResult> LogoutAsync()
{
await HttpContext.SignOutAsync();
return Ok();
}
[HttpGet("info")]
[HttpGet(AuthorityDefaults.Paths.Info)]
[AllowAnonymous]
public async Task<ActionResult<JsonDocument>> GetAuthorityInfoAsync()
{
return Ok();
if (authenticationService is not AuthorityAuthenticationService authService)
{
return BadRequest();
}
var schemesInfos = authService.GetAllSchemeInfos();
var info = new AuthorityInformation
{
IsAuthenticated = false,
SchemeInformation = new SchemeInformation
{
DefaultScheme = authService.Options.DefaultScheme ?? "Unknown",
AvailableSchemes = schemesInfos.ToList()
}
};
return Ok(info);
}
}