init with code from Foxnouns.NET

This commit is contained in:
sam 2024-08-04 15:57:10 +02:00
commit e658366473
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
30 changed files with 1387 additions and 0 deletions

View file

@ -0,0 +1,10 @@
namespace Hydra.Backend.Database.Models;
public class Account : BaseModel
{
public required string Name { get; set; }
public required string EmailAddress { get; set; }
public required string Password { get; set; }
public List<Member> Members { get; init; } = [];
}

View file

@ -0,0 +1,39 @@
using System.Security.Cryptography;
using Hydra.Backend.Utils;
namespace Hydra.Backend.Database.Models;
public class Application : BaseModel
{
public required string ClientId { get; init; }
public required string ClientSecret { get; init; }
public required string Name { get; init; }
public required string[] Scopes { get; init; }
public required string[] RedirectUris { get; set; }
public static Application Create(string name, string[] scopes,
string[] redirectUrls)
{
var clientId = RandomNumberGenerator.GetHexString(32, true);
var clientSecret = AuthUtils.RandomToken();
if (scopes.Except(AuthUtils.Scopes).Any())
{
throw new ArgumentException("Invalid scopes passed to Application.Create", nameof(scopes));
}
if (redirectUrls.Any(s => !AuthUtils.ValidateRedirectUri(s)))
{
throw new ArgumentException("Invalid redirect URLs passed to Application.Create", nameof(redirectUrls));
}
return new Application
{
ClientId = clientId,
ClientSecret = clientSecret,
Name = name,
Scopes = scopes,
RedirectUris = redirectUrls
};
}
}

View file

@ -0,0 +1,9 @@
namespace Hydra.Backend.Database.Models;
public class Member : BaseModel
{
public required string Name { get; set; }
public Ulid AccountId { get; init; }
public Account Account { get; init; } = null!;
}

View file

@ -0,0 +1,17 @@
using NodaTime;
namespace Hydra.Backend.Database.Models;
public class Token : BaseModel
{
public required byte[] Hash { get; init; }
public required Instant ExpiresAt { get; init; }
public required string[] Scopes { get; init; }
public bool ManuallyExpired { get; set; }
public Ulid UserId { get; init; }
public Account Account { get; init; } = null!;
public Ulid ApplicationId { get; set; }
public Application Application { get; set; } = null!;
}