title: Authentication Swagger with JWT Bearer token
body: <p>We are developing a .Net Core 2.1 Web API with JWT Bearer authentication. The application itself will generate and hand out tokens which are to be send to the backend. </p>
  
  <p>While we have everything up and running, i.e. we can send the bearer token from Angular and test it with Postman, Swagger won't send the Bearer token. 
  We have added the Swagger configuration to use a SecurityDefinition as followed, I will post the complete ConfigureServices method:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
      {
          // Add framework services.
          services.AddMvc();
          services.AddCors(options =&gt;
          {
              options.AddPolicy("AllowAllOrigins",
                  policy =&gt; policy.WithOrigins("*").AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
          });
          services.Configure&lt;MvcOptions&gt;(options =&gt;
          {
              options.Filters.Add(new CorsAuthorizationFilterFactory("AllowAllOrigins"));
          });
  
          ServiceInstaller.Install(services, Configuration);
  
          // api user claim policy
          services.AddAuthorization(options =&gt;
          {
              var authorizationPolicy = new AuthorizationPolicyBuilder()
                  .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                  .RequireAuthenticatedUser().Build();
              options.AddPolicy("Bearer", authorizationPolicy);
          });
          // add identity
          var builder = services.AddIdentityCore&lt;AppUser&gt;(o =&gt;
          {
              // configure identity options
              o.Password.RequireDigit = false;
              o.Password.RequireLowercase = false;
              o.Password.RequireUppercase = false;
              o.Password.RequireNonAlphanumeric = false;
              o.Password.RequiredLength = 6;
          });
          builder = new IdentityBuilder(builder.UserType, typeof(IdentityRole), builder.Services);
          builder.AddEntityFrameworkStores&lt;ApplicationDbContext&gt;().AddDefaultTokenProviders();
  
          var keyByteArray = Encoding.ASCII.GetBytes("placekeyhere");
          var signingKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(keyByteArray);
          services.AddAuthentication(options =&gt; { options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(
              options =&gt;
              {
                  options.TokenValidationParameters = new TokenValidationParameters()
                  {
                      IssuerSigningKey = signingKey,
                      ValidAudience = "Audience",
                      ValidIssuer = "Issuer",
                      ValidateIssuerSigningKey = true,
                      ValidateLifetime = true,
                      ClockSkew = TimeSpan.FromMinutes(0)
                  };
              });
          // Configure JwtIssuerOptions
          services.Configure&lt;JwtIssuerOptions&gt;(options =&gt;
          {
              options.Issuer = "Issuer";
              options.Audience = "Audience";
              options.SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256);
          });
  
          // Register the Swagger generator, defining one or more Swagger documents
          services.AddSwaggerGen(c =&gt;
          {
              c.SwaggerDoc("v1", new Info { Title = "AppName", Version = "v1" });
              c.OperationFilter&lt;UploadOperation&gt;();
              c.AddSecurityDefinition("Authorization", new ApiKeyScheme
              {
                  Description =
                      "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                  Name = "Authorization",
                  In = "header",
                  Type = "apiKey",
              });
          });
      }
  </code></pre>
  
  <p>This does add the Authenticate option to the top of the screen. In the configure method we tell the application to actually use the authentication:</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          app.UseAuthentication();
          if (env.IsDevelopment())
          {
              // Enable middleware to serve generated Swagger as a JSON endpoint.
              app.UseCors();
              app.UseSwagger();
              // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
              app.UseSwaggerUI(c =&gt; { c.SwaggerEndpoint("/swagger/v1/swagger.json", "AppName"); });
          }
          app.UseMvc();
      }
  </code></pre>
  
  <p>However when we authenticate ourselves with a token, the curl for the function does not show the Bearer token. It looks like Swagger does not send the token to the backend. </p>
  
  <p>We use .Net Core 2.1 and Swagger 2.3. Any help would be appreciated, thank you.</p>