title: HeaderHandler by AuthorizationHandler : No authenticationScheme was specified, and there was no DefaultChallengeScheme found
body: <p>I'm trying to handle Headers obbligatoriety for an asp.net core web api proj using <em><strong>AuthorizationHandler</strong></em></p>
  <p>I wrote my Handler and Requirement classes:</p>
  <p><strong>Handler class</strong>:</p>
  <pre><code>public class HttpHeaderHandler : AuthorizationHandler&lt;HttpHeaderRequirement&gt;
      {
          private readonly IHttpContextAccessor _httpContextAccessor = null;
          private readonly ILogger&lt;HttpHeaderHandler&gt; _logger;
  
          public HttpHeaderHandler(IHttpContextAccessor httpContextAccessor, ILogger&lt;HttpHeaderHandler&gt; logger)
          {
              _httpContextAccessor = httpContextAccessor;
              _logger = logger;
          }
  
          protected override Task HandleRequirementAsync(
              AuthorizationHandlerContext context,
              HttpHeaderRequirement requirement)
          {
              if (_httpContextAccessor?.HttpContext?.Request?.Headers != null &amp;&amp;
                  !string.IsNullOrEmpty(_httpContextAccessor.HttpContext.Request.Headers[requirement.Header]))
              {
                  context.Succeed(requirement);
              }
              else
              {
                  context.Fail();
                  _logger.LogWarning($&quot;Policy validation for header {requirement.Header} failed&quot;);
              }
  
              return Task.CompletedTask;
          }
      }
  </code></pre>
  <p><strong>Requirement class</strong></p>
  <pre><code>public class HttpHeaderRequirement : IAuthorizationRequirement
      {
          public HttpHeaderRequirement(string header)
          {
              Header = header;
          }
  
          public string Header { get; }
      }
  </code></pre>
  <p>So I added it into the ConfigurationServices method:</p>
  <pre><code>public void ConfigureServices(IServiceCollection services)
          {
              services.AddControllers();
  
              services.AddMvc();
              services.AddAuthorization(options =&gt;
              {
                  options.AddPolicy(&quot;HttpHeaderRequirement&quot;,
                                    policy =&gt; policy.Requirements.Add(new SRN.Microservice.Commons.Authorization.HttpHeaderRequirement(&quot;Auth_Token&quot;)));
              });
          }
  </code></pre>
  <p>so I've created my Controller class using the Authorization implemented:</p>
  <pre><code>[Produces(&quot;application/json&quot;)]
      [Route(&quot;api/[controller]&quot;)]
      [ApiController]
      [Authorize(Policy = &quot;HttpHeaderRequirement&quot;)]
      public class MyController : ControllerBase
      {
         [....]
      }
  </code></pre>
  <p>When I try to call my API the server returns the following exception:</p>
  <pre><code>System.InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action&lt;AuthenticationOptions&gt; configureOptions).
     at Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, String scheme, AuthenticationProperties properties)
     at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
     at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
  </code></pre>
  <p>Is anyone able to help me?</p>