Skip to content

Instantly share code, notes, and snippets.

@xximjasonxx
Created July 6, 2020 02:24
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 xximjasonxx/43dce2a56a538215ffffde46b7c941eb to your computer and use it in GitHub Desktop.
Save xximjasonxx/43dce2a56a538215ffffde46b7c941eb to your computer and use it in GitHub Desktop.
public class IsWeathermanAuthorizationHandler : AuthorizationHandler<IsWeathermanAuthorizationRequirement>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, IsWeathermanAuthorizationRequirement requirement)
{
var permission = context.User?.Claims?.FirstOrDefault(x => x.Type == "permissions" && x.Value == requirement.ValidPermission);
if (permission != null)
context.Succeed(requirement);
return Task.CompletedTask;
}
}
public class IsWeathermanAuthorizationRequirement : IAuthorizationRequirement
{
public string ValidPermission = "read:weather";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment