feat: initial working discord authentication

This commit is contained in:
sam 2024-06-13 02:23:55 +02:00
parent 6186eda092
commit a7950671e1
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
12 changed files with 262 additions and 25 deletions

View file

@ -0,0 +1,21 @@
using Foxnouns.Backend.Services;
using Foxnouns.Backend.Utils;
using NodaTime;
namespace Foxnouns.Backend.Extensions;
public static class KeyCacheExtensions
{
public static async Task<string> GenerateAuthStateAsync(this KeyCacheService keyCacheSvc)
{
var state = OauthUtils.RandomToken();
await keyCacheSvc.SetKeyAsync($"oauth_state:{state}", "", Duration.FromMinutes(10));
return state;
}
public static async Task ValidateAuthStateAsync(this KeyCacheService keyCacheSvc, string state)
{
var val = await keyCacheSvc.GetKeyAsync($"oauth_state:{state}", delete: true);
if (val == null) throw new ApiError.BadRequest("Invalid OAuth state");
}
}