Created
August 9, 2022 04:09
-
-
Save Mgs25/ee6789e6de3a01af817df74d198a59cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var builder = WebApplication.CreateBuilder(args); | |
builder.Services.AddControllers(); | |
builder.Services.AddEndpointsApiExplorer(); | |
builder.Services.AddSwaggerGen(o => | |
{ | |
o.AddSecurityDefinition("basic", new OpenApiSecurityScheme | |
{ | |
Name = "Authorization", | |
In = ParameterLocation.Header, | |
Scheme = "basic", | |
Type = SecuritySchemeType.Http, | |
Description = "Basic Authentication using http security scheme" | |
}); | |
o.AddSecurityRequirement(new OpenApiSecurityRequirement { | |
{ | |
new OpenApiSecurityScheme { | |
Reference = new OpenApiReference { | |
Type = ReferenceType.SecurityScheme, | |
Id = "basic" | |
} | |
}, | |
new string[] { } | |
} | |
}); | |
}); | |
builder.Services.AddAuthentication("BasicAuthentication").AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null); | |
var app = builder.Build(); | |
// Configure the HTTP request pipeline. | |
if (app.Environment.IsDevelopment()) | |
{ | |
app.UseSwagger(); | |
app.UseSwaggerUI(); | |
} | |
app.UseHttpsRedirection(); | |
app.UseAuthentication(); | |
app.UseAuthorization(); | |
app.MapControllers(); | |
app.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment