builder.Services.AddSwaggerGen(options => { OpenApiSecurityScheme scheme = new OpenApiSecurityScheme() { Description = "Authorization header, ex:'Bearer 123456abcdef'", Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Authorization" }, Scheme = "oauth2", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, }; options.AddSecurityDefinition("Authorization", scheme); OpenApiSecurityRequirement requirement = new OpenApiSecurityRequirement(); requirement[scheme] = new List<string>(); options.AddSecurityRequirement(requirement); });
右上会出现Authorize按钮