source: src/FinkiChattery/FinkiChattery.Api/ApplicationServices/Authentication/CurrentUserIsOfRoleRequirementHandler.cs@ f3c4950

dev
Last change on this file since f3c4950 was 7146ebb, checked in by Стојков Марко <mst@…>, 3 years ago

Ask question endpoint

  • Property mode set to 100644
File size: 843 bytes
Line 
1using FinkiChattery.Common.User;
2using Microsoft.AspNetCore.Authorization;
3using System.Threading.Tasks;
4
5namespace FinkiChattery.Api.ApplicationServices.Authentication
6{
7 public class CurrentUserIsOfRoleRequirementHandler : AuthorizationHandler<CurrentUserIsOfRoleRequirement>
8 {
9 public CurrentUserIsOfRoleRequirementHandler(ICurrentUser currentUser)
10 {
11 CurrentUser = currentUser;
12 }
13
14 public ICurrentUser CurrentUser { get; }
15
16 protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, CurrentUserIsOfRoleRequirement requirement)
17 {
18 if (CurrentUser.Role != requirement.UserRole)
19 {
20 context.Fail();
21 }
22
23 context.Succeed(requirement);
24 return Task.CompletedTask;
25 }
26 }
27}
Note: See TracBrowser for help on using the repository browser.