title: Possible to run all handlers for a policy in-line instead of with an attribute?
body: <p>On most of my APIs, I simply do authorization like this:</p>
  
  <pre><code>[Authorize(Policy = "Foo")]
  public MyApi()
  </code></pre>
  
  <p>I get this policy from a NuGet though and can't modify it. </p>
  
  <p>For some of my APIs, I don't always want to have this policy. This needs to get figured out at runtime based on some config. I'd like some way to run this in-line, and ensure all the handlers that are setup run.</p>
  
  <p>After a lot of searching i've found that I create an <code>IAuthorizationService</code>, and use that to call <code>AuthorizeAsync</code>. This seems like it's what I want, but the issue i'm running into now is that all the handlers rely on an <code>AuthorizationFilterContext</code> as the resource on the context. This seems to happen automatically when the Authorization is done through the attribute, but not through the call to AuthorizeAsync. It needs to be passed in manually in this case. My code right now looks like this:</p>
  
  <pre><code>public MyApi()
  {
      var allowed = await _authorizationService.AuthorizeAsync(User, null, "Foo").ConfigureAwait(false);
  }
  </code></pre>
  
  <p>This seems to go through all my handlers correctly, but they don't work due to missing the <code>AuthorizationFilterContext</code>. </p>
  
  <p>1) Is this the correct approach to begin with, or is there some other way to do this in-line? I'm guessing there's probably some way to create my own policy that wraps this one and I can check the config there, but if there's a simple in-line approach i'd prefer that.</p>
  
  <p>2) If this way is valid, is there a good way to get the <code>AuthorizationFilterContext</code>? I've tried creating it manually, but i'm afraid this isn't actually correct without passing in more data from the context, but I can't find any good examples/doc:</p>
  
  <p><code>new AuthorizationFilterContext(new ActionContext(HttpContext, HttpContext.GetRouteData(), new ActionDescriptor()), new IFilterMetadata[] { });</code></p>