title: Swashbuckle .NET Core Custom Authorization Header does not reflect in any API Request
body: <p>For the past couple of days, I've been reading up the documentation thoroughly to implement custom authorisation header support for Swashbuckle.AspNetCore 5.x.x and have been unable to propagate SwaggerUI to properly send API requests from the API docs to any of the APIs (The APIs get hit but it always fails at my Authorize attribute because the header key the contains the API Key is empty).</p>
  <p>I've also stumbled upon these questions:</p>
  <ol>
  <li><a href="https://stackoverflow.com/questions/58197244/swaggerui-with-netcore-3-0-bearer-token-authorization">SwaggerUI with .NetCore 3.0 bearer token authorization</a></li>
  <li><a href="https://stackoverflow.com/questions/48985240/authorization-for-jwt-bearer-in-swashbuckle-net-core-2">Authorization for JWT bearer in Swashbuckle .NET Core 2</a></li>
  <li><a href="https://stackoverflow.com/questions/57943550/how-to-document-api-key-authentication-using-swashbuckle-aspnetcore-v5-0-0-rc2">How to document API Key authentication using Swashbuckle.AspNetCore v5.0.0-rc2</a></li>
  </ol>
  <p>I'm on 5.2.0 on all of Swashbuckle's packages with .NET Core 3.1.2.</p>
  <p>Doesn't seem to work! :(</p>
  <p>Here's my <code>ConfigureServices</code> for Authentication, authorisation and Swagger DI</p>
  <pre><code>services.AddAuthentication(options =&gt;
              {
                  options.DefaultScheme = ApiKeyAuthenticationOptions.DefaultScheme;
                  options.DefaultAuthenticateScheme = ApiKeyAuthenticationOptions.DefaultScheme;
              })
                  .AddScheme&lt;ApiKeyAuthenticationOptions, ApiKeyAuthenticationHandler&gt;(
                      ApiKeyAuthenticationOptions.DefaultScheme, o =&gt; { });
  
              services.AddAuthorization(options =&gt;
              {
                  var defaultAuthorizationPolicyBuilder = new AuthorizationPolicyBuilder(
                      ApiKeyAuthenticationOptions.DefaultScheme);
  
                  defaultAuthorizationPolicyBuilder = 
                      defaultAuthorizationPolicyBuilder.RequireAuthenticatedUser();
  
                  options.DefaultPolicy = defaultAuthorizationPolicyBuilder.Build();
              });
  
              services.AddSwaggerGen(config =&gt;
              {
                  config.SwaggerDoc(GlobalApiVariables.CURRENT_API_VERSION, new OpenApiInfo {
                      Title = &quot;XXXX API&quot;, 
                      Version = GlobalApiVariables.CURRENT_API_REVISION.ToString()
                  });
  
                  config.EnableAnnotations();
  
                  // Adds &quot;(Auth)&quot; to the summary so that you can see which endpoints have Authorization
                  config.OperationFilter&lt;AppendAuthorizeToSummaryOperationFilter&gt;();
                  // or use the generic method, e.g. c.OperationFilter&lt;AppendAuthorizeToSummaryOperationFilter&lt;MyCustomAttribute&gt;&gt;();
                  
                  // [SwaggerRequestExample] &amp; [SwaggerResponseExample]
                  // version &lt; 3.0 like this: c.OperationFilter&lt;ExamplesOperationFilter&gt;(); 
                  // version 3.0 like this: c.AddSwaggerExamples(services.BuildServiceProvider());
                  // version &gt; 4.0 like this:
                  config.ExampleFilters();
                  config.OperationFilter&lt;AddResponseHeadersFilter&gt;(); // [SwaggerResponseHeader]
                  
                  // Locate the XML file being generated by .NET Core
                  var filePath = Path.Combine(AppContext.BaseDirectory, 
                      $&quot;{Assembly.GetExecutingAssembly().GetName().Name}.xml&quot;);
                  config.IncludeXmlComments(filePath);
                  
                  // Define the Api Key scheme that's in use (i.e. Implicit Flow)
                  config.AddSecurityDefinition(ApiKeyAuthenticationOptions.DefaultScheme, new OpenApiSecurityScheme
                  {
                      Description = &quot;Testtest&quot;,
                      In = ParameterLocation.Header,
                      Name = ApiKeyAuthenticationOptions.HeaderKey,
                      Type = SecuritySchemeType.ApiKey,
                      Flows = new OpenApiOAuthFlows
                      {
                          Implicit = new OpenApiOAuthFlow
                          {
                              AuthorizationUrl = new Uri(&quot;/connect/validate&quot;, UriKind.Relative),
                              Scopes = new Dictionary&lt;string, string&gt;
                              {
                                  { &quot;readAccess&quot;, &quot;Access read operations&quot; },
                                  { &quot;writeAccess&quot;, &quot;Access write operations&quot; }
                              }
                          }
                      }
                  });
  
                  // add Security information to each operation for OAuth2
                  config.OperationFilter&lt;SecurityRequirementsOperationFilter&gt;();
  
                  config.AddSecurityRequirement(new OpenApiSecurityRequirement
                  {
                      {
                          new OpenApiSecurityScheme
                          {
                              Reference = new OpenApiReference
                              {
                                  Type = ReferenceType.SecurityScheme, 
                                  Id = ApiKeyAuthenticationOptions.DefaultScheme
                              }
                          },
                          new[] { &quot;readAccess&quot;, &quot;writeAccess&quot; }
                      }
                  });
              });
              services.AddSwaggerExamplesFromAssemblies(Assembly.GetEntryAssembly());
  </code></pre>
  <p>And also, in <code>Configure</code> I added:</p>
  <pre><code>app.UseSwagger(c =&gt;
              {
                  c.RouteTemplate = &quot;/{documentName}/swagger.json&quot;;
              });
              
              app.UseSwaggerUI(c =&gt;
              {
                  c.DocumentTitle = &quot;XXXXX Documentation&quot;;
                  c.RoutePrefix = &quot;&quot;;
                  c.SwaggerEndpoint($&quot;/{GlobalApiVariables.CURRENT_API_VERSION}/swagger.json&quot;, 
                      $&quot;XXXX v{GlobalApiVariables.CURRENT_API_REVISION}&quot;);
                  c.OAuthClientSecret(ApiKeyAuthenticationOptions.HeaderKey);
              });
  </code></pre>
  <p>Here's <code>ApiKeyAuthenticationOptions</code> if you require it:</p>
  <pre><code>public class ApiKeyAuthenticationOptions : AuthenticationSchemeOptions
      {
          public const string DefaultScheme = &quot;API Key&quot;;
          public string Scheme =&gt; DefaultScheme;
          public string AuthenticationType = DefaultScheme;
          public const string HeaderKey = &quot;X-Api-Key&quot;;
      }
  </code></pre>
  <p>Also, here's the test:
  <a href="https://i.stack.imgur.com/6svtT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6svtT.png" alt="enter image description here" /></a></p>
  <p>Let me know what I'm doing wrong, and thank you so much ahead of time!</p>