31 lines
No EOL
875 B
C#
31 lines
No EOL
875 B
C#
using System.Security.Cryptography;
|
|
using IdentityShroud.Core.Contracts;
|
|
using IdentityShroud.Core.Messages.Realm;
|
|
using IdentityShroud.Core.Model;
|
|
|
|
namespace IdentityShroud.Core.Services;
|
|
|
|
public record RealmCreateResponse(Realm Realm);
|
|
|
|
public class RealmService(
|
|
Db db,
|
|
IEncryptionService encryptionService)
|
|
{
|
|
public async Task<Result<RealmCreateResponse>> Create(RealmCreateRequest request, CancellationToken ct = default)
|
|
{
|
|
Realm realm = new()
|
|
{
|
|
Id = request.Id ?? Guid.CreateVersion7(),
|
|
Slug = request.Slug,
|
|
Name = request.Description,
|
|
};
|
|
|
|
using RSA rsa = RSA.Create(2048);
|
|
realm.SetPrivateKey(encryptionService, rsa.ExportPkcs8PrivateKey());
|
|
|
|
db.Add(realm);
|
|
await db.SaveChangesAsync(ct);
|
|
|
|
return new RealmCreateResponse(realm);
|
|
}
|
|
} |