Remove old Controllers

This commit is contained in:
2025-04-07 14:28:57 -04:00
parent 133dcf3790
commit 35b640a802
4 changed files with 0 additions and 71 deletions

View File

@@ -1,60 +0,0 @@
using System.Security.Claims;
using Hutopy.Web.Common;
using Hutopy.Web.Common.Security;
using Hutopy.Web.Features.Users;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.Facebook;
using Microsoft.AspNetCore.Mvc;
namespace Hutopy.Web.Controllers;
public class FacebookController(
IdentityService identityService)
: Controller
{
[Microsoft.AspNetCore.Mvc.HttpGet("/api/facebook/sign-in")]
public async Task SignIn()
{
await HttpContext.ChallengeAsync(FacebookDefaults.AuthenticationScheme,
new AuthenticationProperties { RedirectUri = Url.Action("Authorize") });
}
public async Task<IActionResult> Authorize()
{
var authenticateResult = await HttpContext.AuthenticateAsync(FacebookDefaults.AuthenticationScheme);
if (!authenticateResult.Succeeded) return BadRequest();
var claims = authenticateResult.Principal.Claims.ToList();
var name = claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value ?? "";
var email = claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value ?? "";
var givenName = claims.FirstOrDefault(c => c.Type == ClaimTypes.GivenName)?.Value ?? "";
var familyName = claims.FirstOrDefault(c => c.Type == ClaimTypes.Surname)?.Value ?? "";
var claimsIdentity = new ClaimsIdentity(
new List<Claim>
{
new(ClaimTypes.Name, name),
new(ClaimTypes.Email, email),
new(ClaimTypes.GivenName, givenName),
new(ClaimTypes.Surname, familyName)
},
CookieAuthenticationDefaults.AuthenticationScheme);
if (await identityService.FindUserByEmailAsync(email) != null)
{
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity));
return Redirect("/");
}
await identityService.CreateUserAsync(email, givenName, givenName, familyName,
PasswordGenerator.GeneratePassword(8, 10));
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity));
return Redirect("/");
}
}

View File

@@ -21,8 +21,6 @@ public static class DependencyInjection
services.AddHealthChecks()
.AddDbContextCheck<ApplicationDbContext>();
services.AddRazorPages();
services.AddHttpClient();
// Customise default API behaviour

View File

@@ -38,9 +38,6 @@ builder.Services.AddKeyVaultIfConfigured(builder.Configuration);
builder.Services.AddWebServices();
builder.Services.AddAuthorizationAndAuthentication(builder.Configuration);
// TODO: This old tech should be remove - need to move Facebook / Google controllers to FastEndpoints
builder.Services.AddControllers();
builder.Services.AddOpenApiDocument((
configure,
sp) =>
@@ -119,10 +116,6 @@ if (app.Environment.IsDevelopment())
app.UseSwaggerUi(options => options.Path = "/api");
}
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
app.UseFastEndpoints();
app.Run();