72 lines
1.9 KiB
C#
72 lines
1.9 KiB
C#
using DrinkRateAPI.Contexts;
|
|
using DrinkRateAPI.DbEntities;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddAuthorization();
|
|
builder.Services.AddIdentityApiEndpoints<DbApplicationUser>()
|
|
.AddEntityFrameworkStores<ApplicationDbContext>();
|
|
|
|
builder.Services.AddSwaggerGen(c =>
|
|
{
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "You api title", Version = "v1" });
|
|
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 = "Bearer"
|
|
});
|
|
|
|
c.AddSecurityRequirement(new OpenApiSecurityRequirement()
|
|
{
|
|
{
|
|
new OpenApiSecurityScheme
|
|
{
|
|
Reference = new OpenApiReference
|
|
{
|
|
Type = ReferenceType.SecurityScheme,
|
|
Id = "Bearer"
|
|
},
|
|
Scheme = "oauth2",
|
|
Name = "Bearer",
|
|
In = ParameterLocation.Header,
|
|
|
|
},
|
|
new List<string>()
|
|
}
|
|
});
|
|
});
|
|
|
|
builder.Services.AddDbContext<ApplicationDbContext>();
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
app.MapSwagger().RequireAuthorization();
|
|
}
|
|
|
|
app.MapIdentityApi<DbApplicationUser>();
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|