using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Security.Claims; using Microsoft.AspNetCore.Authentication; namespace WebApp.Authentication { public class AuthController : Controller { [HttpPost] [AllowAnonymous] public async Task CookieLogin(string email, string password) { // Based on: https://www.codeproject.com/articles/Understanding-authentication-in-Blazor-and-ASP-NET // TODO: Fix this up // Generate the claims var claims = new List(); claims.Add(new Claim(ClaimTypes.Name, "John Patton")); claims.Add(new Claim(ClaimTypes.Role, "Contributor")); var principal = new ClaimsPrincipal(new ClaimsIdentity(claims, "Auth")); await HttpContext.SignInAsync("Auth", principal).ConfigureAwait(false); return Redirect("/"); } [HttpPost] public async Task CookieLogout() { await HttpContext.SignOutAsync("Auth").ConfigureAwait(false); return Redirect("/login"); } } }