title: Issue with custom Authentication filter asp.net core
body: <p>I'm trying to create a custom authentication filter in ASP.NET Core. Need to use it in the controller to authenticate the JWT provided to me and create a Claim Principal. However when I place the authentication tag above the controller, nothing happens and the controller is getting processed without the authentication.</p>
  <p>The following are the steps which were done:</p>
  <ol>
  <li>Added the app.UseAuthentication() in the startup.cs under</li>
  </ol>
  <pre><code>    Configure(IApplicationBuilder app, IHostingEnvironment env)
       {
          ......
          ......
          app.UseAuthentication();
       }
  </code></pre>
  <ol start="2">
  <li>Created a new class file ProcessAuth in the same project, containing the AuthenticationAsync and ChallengeAsync</li>
  </ol>
  <pre><code>   public class ProcessAuth : Attribute, IAuthenticationFilter
      {
          public bool AllowMultiple { get { return false; } }
  
  
          public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
          {            
              HttpRequestMessage request = context.Request;
              AuthenticationHeaderValue authorization = request.Headers.Authorization;
              
              // More code to be added for validating the JWT
          }
  
          public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
          {
              throw new NotImplementedException(); //sample code
          }
      } 
  </code></pre>
  <ol start="3">
  <li>Addded a reference of this new file in the controller</li>
  <li>Placed the tag [ProcessAuth] at the top of the controller</li>
  </ol>
  <pre><code>    [ProcessAuth]
      [Route(&quot;api/[controller]&quot;)]
      [ApiController] 
  </code></pre>
  <ol start="5">
  <li>Used Postman to send a JSON data, along with the Authorization Header containing a valid JWT token as &quot;Bearer &quot;</li>
  <li>The code just ignores the filter and processes code in the controller and returns the result</li>
  </ol>
  <p>More info:
  If I add <code>[Authorize]</code> to the controller, Postman just returns a <code>401 Unauthorized error</code></p>
  <p>Also checked <a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/authentication-filters" rel="nofollow noreferrer">this URL</a>, but couldn't find the issue.</p>
  <p><strong>Update:</strong> I checked the answers to the similar Stack Overflow questions and followed the same but still the issue remains the same.</p>
  <p><strong>Nuget Packages installed:</strong>
  Microsoft.AspNet.WebApi.Core and also Microsoft.AspNet.WebApi</p>
  <p><strong>Namespaces used:</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net.Http;
  using System.Net.Http.Headers;
  using System.Security.Claims;
  using System.Threading;
  using System.Threading.Tasks;
  using System.Web.Http.Filters;
  using System.Web.Http.Controllers;
  </code></pre>
  <p><a href="https://stackoverflow.com/questions/42845160/web-api-custom-filter-not-firing">Similar Issue - Link</a></p>
  <p>How do I get this to work? Am I missing something?</p>