Implement owned Profile schema and atomic authorized lifecycle
This commit is contained in:
1 parent
523cfbf42e
commit
bfe6ebf5af
24 files changed
+3056
-3
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user