Implement owned Profile schema and atomic authorized lifecycle

This commit is contained in:
Steffen committed 2026-10-14 11:37:12 +02:00
1 parent 523cfbf42e
commit bfe6ebf5af
24 files changed
+3056 -3

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
using System.Security.Claims;
using HealthApp.Contracts;
namespace HealthApp.Security;
public sealed class AccessPolicy(ProfileQueries profiles,ProfessionalAssignments assignments)
{
public async Task<AuthorizedPatientContext?> AuthorizeAsync(ClaimsPrincipal user,Guid actualPatient,bool write,CancellationToken ct)
{
var account=user.FindFirstValue(ClaimTypes.NameIdentifier)!;
bool allowed=user.IsInRole("HealthcareProfessional") ? !write&&assignments.IsAssigned(account,actualPatient) : user.IsInRole("Patient")&&await profiles.ResolveAccountAsync(account,ct)==actualPatient;
return allowed?new AuthorizedPatientContext(actualPatient,write):null;
}
}