public async Task <IActionResult> PerformSurgery() { // or imperatively var canPerformSurgery = await _client.HasPermissionAsync(User, "PerformSurgery"); return(View("Success")); }
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement) { if (await _client.HasPermissionAsync(context.User, requirement.Name)) { context.Succeed(requirement); } }
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, MedicationRequirement requirement) { var user = context.User; var allowed = false; if (await _client.HasPermissionAsync(user, "PrescribeMedication")) { if (requirement.Amount <= 10) { allowed = true; } else { allowed = await _client.IsInRoleAsync(user, "doctor"); } if (allowed || requirement.MedicationName == "placebo") { context.Succeed(requirement); } } }