title: Bearer authentication in Swagger UI, when migrating to Swashbuckle.AspNetCore version 5
body: <p>I'm trying to migrate from version 4.0.1 to 5.0.0-rc2 of Swashbuckle in a .NET Core 3 Preview 5 Web API project.</p>
  
  <p>I've got the project compiling and the Swagger UI working, but I can't get Bearer authentication to work, which I think is due to me not setting up the new format security correctly.</p>
  
  <p>This is my old code that worked in version 4:</p>
  
  <pre><code>c.AddSecurityDefinition("Bearer", new ApiKeyScheme
  {
      Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
      Name = "Authorization",
      In = "header",
      Type = "apiKey"
  });
  
  var security = new Dictionary&lt;string, IEnumerable&lt;string&gt;&gt;
  {
      {"Bearer", new string[] { }},
  };
  
  c.AddSecurityRequirement(security);
  </code></pre>
  
  <p>And this is what I've changed it to for v5:</p>
  
  <pre><code>c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
  {
      Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
      Name = "Authorization",
      In = ParameterLocation.Header,
      Type = SecuritySchemeType.ApiKey,
      Scheme = "tomsAuth"
  });
  
  c.AddSecurityRequirement(new OpenApiSecurityRequirement
  {
      {
          new OpenApiSecurityScheme
          {
              Reference = new OpenApiReference {
                  Type = ReferenceType.SecurityScheme,
                  Id = "tomsAuth" }
          }, new List&lt;string&gt;() }
  });
  </code></pre>
  
  <p>I think my issue is probably in this part of the code:</p>
  
  <pre><code>        new OpenApiSecurityScheme
          {
              Reference = new OpenApiReference {
                  Type = ReferenceType.SecurityScheme,
                  Id = "tomsAuth" }
          }, new List&lt;string&gt;() }
  </code></pre>
  
  <p>I think that bit should probably have "Bearer" in it somewhere, but I'm not sure where?</p>
  
  <h3>Additional info</h3>
  
  <p>This is how I'm setting up the JWT authentication in the first place.  This code hasn't changed and was working when I was using Swashbuckle 4.0.1:</p>
  
  <pre><code>    var appSettings = appSettingsSection.Get&lt;AppSettings&gt;();
      var key = Encoding.ASCII.GetBytes(appSettings.Secret);
  
      services.AddAuthentication(x =&gt;
      {
          x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
          x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
      })
      .AddJwtBearer(x =&gt;
      {
          x.Events = new JwtBearerEvents
          {
              OnTokenValidated = context =&gt;
              {
                  var userService = context.HttpContext.RequestServices.GetRequiredService&lt;IApiUserService&gt;();
                  var userId = int.Parse(context.Principal.Identity.Name);
                  var user = userService.GetById(userId);
                  if (user == null)
                  {
                      // return unauthorized if user no longer exists
                      context.Fail("Unauthorized");
                  }
  
                  return Task.CompletedTask;
              }
          };
          x.RequireHttpsMetadata = false;
          x.SaveToken = true;
          x.TokenValidationParameters = new TokenValidationParameters
          {
              ValidateIssuerSigningKey = true,
              IssuerSigningKey = new SymmetricSecurityKey(key),
              ValidateIssuer = false,
              ValidateAudience = false
          };
      });
  </code></pre>