Remove old Controllers
This commit is contained in:
2
backend/.gitignore
vendored
2
backend/.gitignore
vendored
@@ -37,8 +37,6 @@ bld/
|
|||||||
|
|
||||||
# Visual Studio 2015/2017 cache/options directory
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
.vs/
|
.vs/
|
||||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
|
||||||
#wwwroot/
|
|
||||||
|
|
||||||
# Visual Studio 2017 auto generated files
|
# Visual Studio 2017 auto generated files
|
||||||
Generated\ Files/
|
Generated\ Files/
|
||||||
|
|||||||
@@ -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("/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,8 +21,6 @@ public static class DependencyInjection
|
|||||||
services.AddHealthChecks()
|
services.AddHealthChecks()
|
||||||
.AddDbContextCheck<ApplicationDbContext>();
|
.AddDbContextCheck<ApplicationDbContext>();
|
||||||
|
|
||||||
services.AddRazorPages();
|
|
||||||
|
|
||||||
services.AddHttpClient();
|
services.AddHttpClient();
|
||||||
|
|
||||||
// Customise default API behaviour
|
// Customise default API behaviour
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ builder.Services.AddKeyVaultIfConfigured(builder.Configuration);
|
|||||||
builder.Services.AddWebServices();
|
builder.Services.AddWebServices();
|
||||||
builder.Services.AddAuthorizationAndAuthentication(builder.Configuration);
|
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((
|
builder.Services.AddOpenApiDocument((
|
||||||
configure,
|
configure,
|
||||||
sp) =>
|
sp) =>
|
||||||
@@ -119,10 +116,6 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwaggerUi(options => options.Path = "/api");
|
app.UseSwaggerUi(options => options.Path = "/api");
|
||||||
}
|
}
|
||||||
|
|
||||||
app.MapControllerRoute(
|
|
||||||
name: "default",
|
|
||||||
pattern: "{controller}/{action=Index}/{id?}");
|
|
||||||
|
|
||||||
app.UseFastEndpoints();
|
app.UseFastEndpoints();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
Reference in New Issue
Block a user