feat(backend): move internal endpoints to /api/internal
This commit is contained in:
parent
eac0a17473
commit
06f7019330
9 changed files with 39 additions and 27 deletions
|
@ -1,14 +1,18 @@
|
|||
using System.Web;
|
||||
using Foxnouns.Backend.Database;
|
||||
using Foxnouns.Backend.Extensions;
|
||||
using Foxnouns.Backend.Middleware;
|
||||
using Foxnouns.Backend.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using NodaTime;
|
||||
|
||||
namespace Foxnouns.Backend.Controllers.Authentication;
|
||||
|
||||
[Route("/api/v2/auth")]
|
||||
public class AuthController(Config config, KeyCacheService keyCache, ILogger logger) : ApiControllerBase
|
||||
[Route("/api/internal/auth")]
|
||||
public class AuthController(Config config, DatabaseContext db, KeyCacheService keyCache, ILogger logger)
|
||||
: ApiControllerBase
|
||||
{
|
||||
private readonly ILogger _logger = logger.ForContext<AuthController>();
|
||||
|
||||
|
@ -61,4 +65,15 @@ public class AuthController(Config config, KeyCacheService keyCache, ILogger log
|
|||
public record OauthRegisterRequest(string Ticket, string Username);
|
||||
|
||||
public record CallbackRequest(string Code, string State);
|
||||
|
||||
[HttpPost("force-log-out")]
|
||||
[Authorize("identify")]
|
||||
public async Task<IActionResult> ForceLogoutAsync()
|
||||
{
|
||||
_logger.Information("Invalidating all tokens for user {UserId}", CurrentUser!.Id);
|
||||
await db.Tokens.Where(t => t.UserId == CurrentUser.Id)
|
||||
.ExecuteUpdateAsync(s => s.SetProperty(t => t.ManuallyExpired, true));
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ using NodaTime;
|
|||
|
||||
namespace Foxnouns.Backend.Controllers.Authentication;
|
||||
|
||||
[Route("/api/v2/auth/discord")]
|
||||
[Route("/api/internal/auth/discord")]
|
||||
public class DiscordAuthController(
|
||||
[UsedImplicitly] Config config,
|
||||
ILogger logger,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Foxnouns.Backend.Database;
|
||||
using Foxnouns.Backend.Database.Models;
|
||||
using Foxnouns.Backend.Extensions;
|
||||
using Foxnouns.Backend.Middleware;
|
||||
using Foxnouns.Backend.Services;
|
||||
using Foxnouns.Backend.Utils;
|
||||
using JetBrains.Annotations;
|
||||
|
@ -10,7 +11,7 @@ using NodaTime;
|
|||
|
||||
namespace Foxnouns.Backend.Controllers.Authentication;
|
||||
|
||||
[Route("/api/v2/auth/email")]
|
||||
[Route("/api/internal/auth/email")]
|
||||
public class EmailAuthController(
|
||||
[UsedImplicitly] Config config,
|
||||
DatabaseContext db,
|
||||
|
@ -123,6 +124,17 @@ public class EmailAuthController(
|
|||
));
|
||||
}
|
||||
|
||||
[HttpPost("add")]
|
||||
[Authorize("*")]
|
||||
public async Task<IActionResult> AddEmailAddressAsync()
|
||||
{
|
||||
_logger.Information("beep");
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
public record AddEmailAddressRequest(string Email, string Password);
|
||||
|
||||
private void CheckRequirements()
|
||||
{
|
||||
if (!config.EmailAuth.Enabled)
|
||||
|
|
|
@ -1,35 +1,17 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using Foxnouns.Backend.Database;
|
||||
using Foxnouns.Backend.Middleware;
|
||||
using Foxnouns.Backend.Utils;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using Microsoft.AspNetCore.Routing.Template;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Foxnouns.Backend.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("/api/internal")]
|
||||
public partial class InternalController(ILogger logger, DatabaseContext db) : ControllerBase
|
||||
public partial class InternalController(DatabaseContext db) : ControllerBase
|
||||
{
|
||||
private readonly ILogger _logger = logger.ForContext<InternalController>();
|
||||
|
||||
[HttpPost("force-log-out")]
|
||||
[Authenticate]
|
||||
[Authorize("identify")]
|
||||
public async Task<IActionResult> ForceLogoutAsync()
|
||||
{
|
||||
var user = HttpContext.GetUser()!;
|
||||
|
||||
_logger.Information("Invalidating all tokens for user {UserId}", user.Id);
|
||||
await db.Tokens.Where(t => t.UserId == user.Id)
|
||||
.ExecuteUpdateAsync(s => s.SetProperty(t => t.ManuallyExpired, true));
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"(\{\w+\})")]
|
||||
private static partial Regex PathVarRegex();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue