Skip to content

Instantly share code, notes, and snippets.

@balteravishay
Created November 7, 2021 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balteravishay/1c99a1cf9d478e10b046add66e6f35e3 to your computer and use it in GitHub Desktop.
Save balteravishay/1c99a1cf9d478e10b046add66e6f35e3 to your computer and use it in GitHub Desktop.
Reader Access
namespace PMVProxy.API.Middleware
{
using Hl7.Fhir.Model;
...
internal class OwnerAccess : IAccessByRole
{
...
public async System.Threading.Tasks.Task Access<TResource>(TResource resource,
string userFhirId, IFhirService fhirService) where TResource : Resource
{
var resourceId = $"{resource.TypeName}/{resource.Id}";
if (await fhirService.ExistsAsync<Consent>(new string[] {
$"data={resourceId}" , $"actor={userFhirId}", "status=active"}))
{
_logger.LogInformation($"user {userFhirId} has consent over resource {resource.Id}");
return;
}
else
{
_logger.LogWarning($"user {userFhirId} does not have consent to read {resource.Id}");
throw new AuthorizationException("you do not have consent for this document");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment