add a bunch of authentication stuff

This commit is contained in:
sam 2024-05-19 17:20:45 +02:00
parent 996e59f49a
commit aca83fa1ef
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
22 changed files with 681 additions and 28 deletions

View file

@ -1,8 +1,26 @@
using System.Security.Cryptography;
using Foxchat.Core.Utils;
using NodaTime;
namespace Foxchat.Identity.Database.Models;
public class Token
public class Token : BaseModel
{
public Ulid Id { get; init; } = Ulid.NewUlid();
public byte[] Hash { get; set; } = null!;
public string[] Scopes { get; set; } = [];
public Instant Expires { get; set; }
public Ulid AccountId { get; set; }
public Account Account { get; set; } = null!;
}
public Ulid ApplicationId { get; set; }
public Application Application { get; set; } = null!;
public static (string, byte[]) Generate()
{
var token = CryptoUtils.RandomToken(48);
var hash = SHA512.HashData(Convert.FromBase64String(token));
return (token, hash);
}
}