Recreated solution with web app template. Improved theme. Switched to ShadcnBlazor library
This commit is contained in:
65
Moonlight.Api/Http/Controllers/AuthController.cs
Normal file
65
Moonlight.Api/Http/Controllers/AuthController.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moonlight.Shared.Http.Responses.Auth;
|
||||
|
||||
namespace Moonlight.Api.Http.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/auth")]
|
||||
public class AuthController : Controller
|
||||
{
|
||||
private readonly IAuthenticationSchemeProvider SchemeProvider;
|
||||
|
||||
public AuthController(IAuthenticationSchemeProvider schemeProvider)
|
||||
{
|
||||
SchemeProvider = schemeProvider;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<SchemeResponse[]>> GetSchemesAsync()
|
||||
{
|
||||
var schemes = await SchemeProvider.GetAllSchemesAsync();
|
||||
|
||||
return schemes
|
||||
.Where(scheme => !string.IsNullOrWhiteSpace(scheme.DisplayName))
|
||||
.Select(scheme => new SchemeResponse(scheme.Name, scheme.DisplayName!))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
[HttpGet("{schemeName:alpha}")]
|
||||
public async Task<ActionResult> StartAsync([FromRoute] string schemeName)
|
||||
{
|
||||
var scheme = await SchemeProvider.GetSchemeAsync(schemeName);
|
||||
|
||||
if (scheme == null || string.IsNullOrWhiteSpace(scheme.DisplayName))
|
||||
return Problem("Invalid authentication scheme name", statusCode: 400);
|
||||
|
||||
return Challenge(new AuthenticationProperties()
|
||||
{
|
||||
RedirectUri = "/"
|
||||
}, scheme.Name);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("claims")]
|
||||
public Task<ActionResult<ClaimResponse[]>> GetClaimsAsync()
|
||||
{
|
||||
var result = User.Claims
|
||||
.Select(claim => new ClaimResponse(claim.Type, claim.Value))
|
||||
.ToArray();
|
||||
|
||||
return Task.FromResult<ActionResult<ClaimResponse[]>>(result);
|
||||
}
|
||||
|
||||
[HttpGet("logout")]
|
||||
public Task<ActionResult> LogoutAsync()
|
||||
{
|
||||
return Task.FromResult<ActionResult>(
|
||||
SignOut(new AuthenticationProperties()
|
||||
{
|
||||
RedirectUri = "/"
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user