I'm implementing custom authentication filter and using "Passive Attributes" approach described here: http://blog.ploeh.dk/2014/06/13/passive-attributes/
DI works as expected but I can't figure out how to read custom attributes from controller itself? I would like both individual actions and whole controllers to support this functionality.
Example of controller:
[TokenAuth] // This attribute not "visible"
public class SupportController : ApiController
{
private ISecurityService SecurityService { get; }
public SupportController(ISecurityService securityService)
{
this.SecurityService = securityService;
}
[TokenAuth] // This attribute works
[HttpGet]
public object StartupData()
{
return "Startup data";
}
}
This is portion of filter code where I read custom attribute:
public Task<HttpResponseMessage> ExecuteActionFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func<Task<HttpResponseMessage>> continuation)
{
var tokenAuthAttribute = actionContext.ActionDescriptor.GetCustomAttributes<TokenAuthAttribute>(true).SingleOrDefault();
// This line below exists unless attribute placed on method/action
if (tokenAuthAttribute == null) return continuation();
var req = actionContext.Request;
Is there any way to access controller's attributes?
ControllerDescriptorproperty?