47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using System.Security.Claims;
|
|
using System.Text.Json;
|
|
using IntegryControlPanel.Components.Account.Pages;
|
|
using IntegryControlPanel.Components.Account.Pages.Manage;
|
|
using IntegryControlPanel.Data;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.AspNetCore.Http.Extensions;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Primitives;
|
|
|
|
namespace Microsoft.AspNetCore.Routing
|
|
{
|
|
internal static class IdentityComponentsEndpointRouteBuilderExtensions
|
|
{
|
|
// These endpoints are required by the Identity Razor components defined in the /Components/Account/Pages directory of this project.
|
|
public static IEndpointConventionBuilder MapAdditionalIdentityEndpoints(this IEndpointRouteBuilder endpoints)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(endpoints);
|
|
|
|
var accountGroup = endpoints.MapGroup("/Account");
|
|
|
|
accountGroup.MapPost("/Logout", async (
|
|
ClaimsPrincipal user,
|
|
[FromServices] SignInManager<ApplicationUser> signInManager,
|
|
[FromForm] string returnUrl) =>
|
|
{
|
|
await signInManager.SignOutAsync();
|
|
return TypedResults.LocalRedirect($"~/{returnUrl}");
|
|
});
|
|
|
|
// Add GET endpoint for logout to handle navigation from WebAssembly client
|
|
accountGroup.MapGet("/Logout", async (
|
|
ClaimsPrincipal user,
|
|
[FromServices] SignInManager<ApplicationUser> signInManager,
|
|
[FromQuery] string? returnUrl) =>
|
|
{
|
|
await signInManager.SignOutAsync();
|
|
return TypedResults.LocalRedirect($"~/{returnUrl ?? "Account/Login"}");
|
|
});
|
|
|
|
return accountGroup;
|
|
}
|
|
}
|
|
}
|