26 lines
695 B
C#
26 lines
695 B
C#
using System.Security.Cryptography;
|
|
using Foxchat.Core.Utils;
|
|
using NodaTime;
|
|
|
|
namespace Foxchat.Identity.Database.Models;
|
|
|
|
public class Token : BaseModel
|
|
{
|
|
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);
|
|
}
|
|
}
|