feat: initial working discord authentication
This commit is contained in:
parent
6186eda092
commit
a7950671e1
12 changed files with 262 additions and 25 deletions
21
Foxnouns.Backend/Extensions/KeyCacheExtensions.cs
Normal file
21
Foxnouns.Backend/Extensions/KeyCacheExtensions.cs
Normal 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");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue