Reworked code around signing keys have key details much more isolated from the other parts of the program.
This commit is contained in:
parent
eb872a4f44
commit
0c6f227049
40 changed files with 474 additions and 281 deletions
|
|
@ -3,6 +3,8 @@ using IdentityShroud.Core.Contracts;
|
|||
using IdentityShroud.Core.Helpers;
|
||||
using IdentityShroud.Core.Messages.Realm;
|
||||
using IdentityShroud.Core.Model;
|
||||
using IdentityShroud.Core.Security.Keys;
|
||||
using IdentityShroud.Core.Security.Keys.Rsa;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace IdentityShroud.Core.Services;
|
||||
|
|
@ -11,8 +13,14 @@ public record RealmCreateResponse(Guid Id, string Slug, string Name);
|
|||
|
||||
public class RealmService(
|
||||
Db db,
|
||||
IKeyProvisioningService keyProvisioningService) : IRealmService
|
||||
IKeyService keyService) : IRealmService
|
||||
{
|
||||
public async Task<Realm?> FindById(Guid id, CancellationToken ct = default)
|
||||
{
|
||||
return await db.Realms
|
||||
.SingleOrDefaultAsync(r => r.Id == id, ct);
|
||||
}
|
||||
|
||||
public async Task<Realm?> FindBySlug(string slug, CancellationToken ct = default)
|
||||
{
|
||||
return await db.Realms
|
||||
|
|
@ -26,8 +34,9 @@ public class RealmService(
|
|||
Id = request.Id ?? Guid.CreateVersion7(),
|
||||
Slug = request.Slug ?? SlugHelper.GenerateSlug(request.Name),
|
||||
Name = request.Name,
|
||||
Keys = [ keyProvisioningService.CreateRsaKey() ],
|
||||
};
|
||||
|
||||
realm.Keys.Add(keyService.CreateKey(GetKeyPolicy(realm)));
|
||||
|
||||
db.Add(realm);
|
||||
await db.SaveChangesAsync(ct);
|
||||
|
|
@ -36,6 +45,14 @@ public class RealmService(
|
|||
realm.Id, realm.Slug, realm.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Place holder for getting policies from the realm and falling back to sane defaults when no policies have been set.
|
||||
/// </summary>
|
||||
/// <param name="_"></param>
|
||||
/// <returns></returns>
|
||||
private KeyPolicy GetKeyPolicy(Realm _) => new RsaKeyPolicy();
|
||||
|
||||
|
||||
public async Task LoadActiveKeys(Realm realm)
|
||||
{
|
||||
await db.Entry(realm).Collection(r => r.Keys)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue