mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-12 19:22:45 +00:00
open source Notesnook API
This commit is contained in:
18
Notesnook.API/Authorization/NotesnookUserRequirement.cs
Normal file
18
Notesnook.API/Authorization/NotesnookUserRequirement.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace Notesnook.API.Authorization
|
||||
{
|
||||
public class NotesnookUserRequirement : AuthorizationHandler<NotesnookUserRequirement>, IAuthorizationRequirement
|
||||
{
|
||||
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, NotesnookUserRequirement requirement)
|
||||
{
|
||||
var isInAudience = context.User.HasClaim("aud", "notesnook");
|
||||
var hasRole = context.User.HasClaim("role", "notesnook");
|
||||
if (isInAudience && hasRole)
|
||||
context.Succeed(requirement);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user