Foxchat.NET/Foxchat.Identity/Database/Models/Token.cs

27 lines
695 B
C#
Raw Normal View History

2024-05-19 17:20:45 +02:00
using System.Security.Cryptography;
using Foxchat.Core.Utils;
using NodaTime;
2024-05-11 15:26:47 +02:00
namespace Foxchat.Identity.Database.Models;
2024-05-19 17:20:45 +02:00
public class Token : BaseModel
2024-05-11 15:26:47 +02:00
{
2024-05-19 17:20:45 +02:00
public byte[] Hash { get; set; } = null!;
public string[] Scopes { get; set; } = [];
public Instant Expires { get; set; }
2024-05-11 15:26:47 +02:00
public Ulid AccountId { get; set; }
public Account Account { get; set; } = null!;
2024-05-19 17:20:45 +02:00
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);
}
}