diff --git a/backend/.gitignore b/backend/.gitignore index d6fda7d..6719306 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -37,8 +37,6 @@ bld/ # Visual Studio 2015/2017 cache/options directory .vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ # Visual Studio 2017 auto generated files Generated\ Files/ diff --git a/backend/src/Web/Controllers/FacebookController.cs b/backend/src/Web/Controllers/FacebookController.cs deleted file mode 100644 index d05c3f3..0000000 --- a/backend/src/Web/Controllers/FacebookController.cs +++ /dev/null @@ -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 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 - { - 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("/"); - } -} diff --git a/backend/src/Web/DependencyInjection.cs b/backend/src/Web/DependencyInjection.cs index cdc4275..1bbb520 100644 --- a/backend/src/Web/DependencyInjection.cs +++ b/backend/src/Web/DependencyInjection.cs @@ -21,8 +21,6 @@ public static class DependencyInjection services.AddHealthChecks() .AddDbContextCheck(); - services.AddRazorPages(); - services.AddHttpClient(); // Customise default API behaviour diff --git a/backend/src/Web/Program.cs b/backend/src/Web/Program.cs index 398cc95..fa8a7f0 100644 --- a/backend/src/Web/Program.cs +++ b/backend/src/Web/Program.cs @@ -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();