75 lines
2 KiB
C#
75 lines
2 KiB
C#
using DrinkRateAPI.Contexts;
|
|
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<IdentityUser>()
|
|
.AddEntityFrameworkStores<IdentityDbContext>();
|
|
|
|
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>()
|
|
}
|
|
});
|
|
});
|
|
|
|
// to do: remove
|
|
builder.Services.AddDbContext<IdentityDbContext>(
|
|
options => options.UseInMemoryDatabase("AppDb"));
|
|
|
|
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<IdentityUser>();
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|