Skip to content

Instantly share code, notes, and snippets.

@WrackedFella
Last active July 5, 2023 13:39
Show Gist options
  • Save WrackedFella/08293716a925cc22e97ed3b74b3aa31b to your computer and use it in GitHub Desktop.
Save WrackedFella/08293716a925cc22e97ed3b74b3aa31b to your computer and use it in GitHub Desktop.
using Microsoft.AspNetCore.Authorization;
namespace Api.Core
{
/// <summary>
/// Role based auth.
/// </summary>
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
public CustomAuthorizeAttribute()
{
// Remove if you're not doing bearer tokens (Like for cookies)
this.AuthenticationSchemes = "Bearer";
this.Roles = EnterpriseRoles.Admin;
}
public CustomAuthorizeAttribute(params string[] roles) : base()
{
this.AuthenticationSchemes = "Bearer";
this.Roles = string.Join(",", roles) + "," + EnterpriseRoles.Admin;
}
public CustomAuthorizeAttribute(string policy) : base(policy)
{
this.AuthenticationSchemes = "Bearer";
this.Roles = EnterpriseRoles.Admin;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment