feat(backend): add RequestDiscordTokenAsync method

This commit is contained in:
sam 2024-06-12 16:19:49 +02:00
parent 2a7bd746aa
commit 6186eda092
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
12 changed files with 230 additions and 22 deletions

View file

@ -6,12 +6,16 @@ using NodaTime;
namespace Foxnouns.Backend.Controllers.Authentication;
[Route("/api/v2/auth")]
public class AuthController(Config config, KeyCacheService keyCacheSvc) : ApiControllerBase
{
public class AuthController(Config config, KeyCacheService keyCacheSvc, ILogger logger) : ApiControllerBase
{
[HttpPost("urls")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(UrlsResponse))]
[ProducesResponseType<UrlsResponse>(StatusCodes.Status200OK)]
public async Task<IActionResult> UrlsAsync()
{
logger.Debug("Generating auth URLs for Discord: {Discord}, Google: {Google}, Tumblr: {Tumblr}",
config.DiscordAuth.Enabled,
config.GoogleAuth.Enabled,
config.TumblrAuth.Enabled);
var state = HttpUtility.UrlEncode(await keyCacheSvc.GenerateAuthStateAsync());
string? discord = null;
if (config.DiscordAuth.ClientId != null && config.DiscordAuth.ClientSecret != null)
@ -35,4 +39,6 @@ public class AuthController(Config config, KeyCacheService keyCacheSvc) : ApiCon
string Token,
Instant ExpiresAt
);
public record CallbackRequest(string Code, string State);
}