Update documentation and gate tag creation behind admin role, create default admin on database seeding
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NSwag;
|
||||
using NSwag.Generation.Processors.Security;
|
||||
using T120B165_ImgBoard.Data;
|
||||
using T120B165_ImgBoard.Models;
|
||||
using T120B165_ImgBoard.Services;
|
||||
@@ -21,8 +24,17 @@ public class Program
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddControllers().AddNewtonsoftJson(
|
||||
options => options.SerializerSettings.Converters.Add(new StringEnumConverter()));
|
||||
builder.Services.AddOpenApiDocument();
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddOpenApiDocument(cfg =>
|
||||
{
|
||||
cfg.OperationProcessors.Add(new OperationSecurityScopeProcessor("auth"));
|
||||
cfg.DocumentProcessors.Add(new SecurityDefinitionAppender("auth", new OpenApiSecurityScheme
|
||||
{
|
||||
Type = OpenApiSecuritySchemeType.Http,
|
||||
In = OpenApiSecurityApiKeyLocation.Header,
|
||||
Scheme = "bearer",
|
||||
BearerFormat = "jwt"
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
builder.Services.AddIdentity<User, IdentityRole>()
|
||||
@@ -84,7 +96,7 @@ public class Program
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
//app.MapOpenApi();
|
||||
app.UseOpenApi();
|
||||
app.UseSwaggerUi();
|
||||
}
|
||||
@@ -95,11 +107,12 @@ public class Program
|
||||
|
||||
var context = services.GetRequiredService<ImgBoardContext>();
|
||||
context.Database.EnsureCreated();
|
||||
DbInitializer.SeedRolesAsync(services).GetAwaiter().GetResult();
|
||||
DbInitializer.SeedAuth(services).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
Reference in New Issue
Block a user