Created
July 6, 2020 02:24
-
-
Save xximjasonxx/43dce2a56a538215ffffde46b7c941eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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