Skip to content

Instantly share code, notes, and snippets.

@JaykeOps
Created January 19, 2018 16:38
Show Gist options
  • Save JaykeOps/c43352ba9369e8370ad1afee1f20cdcb to your computer and use it in GitHub Desktop.
Save JaykeOps/c43352ba9369e8370ad1afee1f20cdcb to your computer and use it in GitHub Desktop.
RequestHandler
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using OpenBlog.Api.Authorization.Requirements;
namespace OpenBlog.Api.Authorization.Handlers
{
public class ResourceOwnerHandler : AuthorizationHandler<ResourceOwnerRequirement, string>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, ResourceOwnerRequirement requirement,
string resource)
{
if (context.User.HasClaim(claim =>
claim.Type == "client_id" && claim.Value == resource))
context.Succeed(requirement);
return Task.CompletedTask;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment