I would like to display components of a navigation tree only if a principal has access to those components (whether roles or policy based).
I am not particularly familiar with MVC core, but reading to date would indicate that I could build a list of what authorization filters will be applied to an action with something like:
public NavigationNodePermissionResolver(ApplicationModel appModel)
{
foreach (var controllerModel in appModel.Controllers)
{
var contextFilters = controllerModel.Filters.OfType<IAsyncAuthorizationFilter>().ToList();
foreach (ActionModel action in controllerModel.Actions)//todo restrain to HttpGet
{
var actionFilters = action.Filters.OfType<IAsyncAuthorizationFilter>().ToList();
}
}
How can I inject an instance of the application model into the instantiator for NavigationNodePermissionResolver?
NavigationNodePermissionResolver itself will be injectable as:
services.TryAddSingleton<INavigationNodePermissionResolver, NavigationNodePermissionResolver>();
edit
the follow on to this question - what to do when I have a list of the IAsyncAuthorizationFilters is in this so question.
as follow up information the ApplicationModel is a property of the ApplicationModelProviderContext which I found out about in this SO answer - it does seem to be roughly what I am after, but it may be the approach I am using to obtain and then execute authorization filters is completely wrong