2023-08-15 22:52:30 -05:00
|
|
|
using DamageAssesment.Api.Attachments.Db;
|
|
|
|
using DamageAssesment.Api.Attachments.Interfaces;
|
|
|
|
using DamageAssesment.Api.Attachments.Providers;
|
2023-09-19 23:32:30 -05:00
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
2023-08-15 22:52:30 -05:00
|
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using Microsoft.Extensions.FileProviders;
|
2023-09-19 23:32:30 -05:00
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
using Microsoft.OpenApi.Models;
|
2023-08-24 20:25:38 -05:00
|
|
|
using System.Reflection;
|
2023-09-19 23:32:30 -05:00
|
|
|
using System.Text;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
2023-09-19 23:32:30 -05:00
|
|
|
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
|
|
|
builder.Services.AddAuthentication(item =>
|
|
|
|
{
|
|
|
|
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
item.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
}).AddJwtBearer(item =>
|
|
|
|
{
|
|
|
|
item.RequireHttpsMetadata = true;
|
|
|
|
item.SaveToken = true;
|
|
|
|
item.TokenValidationParameters = new TokenValidationParameters()
|
|
|
|
{
|
|
|
|
ValidateIssuerSigningKey = true,
|
|
|
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(authkey)),
|
|
|
|
ValidateIssuer = false,
|
|
|
|
ValidateAudience = false,
|
|
|
|
ClockSkew = TimeSpan.Zero
|
|
|
|
};
|
|
|
|
});
|
2023-08-15 22:52:30 -05:00
|
|
|
// Add services to the container.
|
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
2023-08-24 20:25:38 -05:00
|
|
|
//builder.Services.AddSwaggerGen();
|
2023-09-19 23:32:30 -05:00
|
|
|
builder.Services.AddSwaggerGen(options =>
|
2023-08-24 20:25:38 -05:00
|
|
|
{
|
|
|
|
// Include XML comments from your assembly
|
|
|
|
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
|
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
2023-09-19 23:32:30 -05:00
|
|
|
options.IncludeXmlComments(xmlPath);
|
|
|
|
|
|
|
|
OpenApiSecurityScheme securityDefinition = new OpenApiSecurityScheme()
|
|
|
|
{
|
|
|
|
Name = "Bearer",
|
|
|
|
BearerFormat = "JWT",
|
|
|
|
Scheme = "bearer",
|
|
|
|
Description = "Specify the authorization token.",
|
|
|
|
In = ParameterLocation.Header,
|
|
|
|
Type = SecuritySchemeType.Http,
|
|
|
|
};
|
|
|
|
|
|
|
|
options.AddSecurityDefinition("jwt_auth", securityDefinition);
|
|
|
|
|
|
|
|
// Make sure swagger UI requires a Bearer token specified
|
|
|
|
OpenApiSecurityScheme securityScheme = new OpenApiSecurityScheme()
|
|
|
|
{
|
|
|
|
Reference = new OpenApiReference()
|
|
|
|
{
|
|
|
|
Id = "jwt_auth",
|
|
|
|
Type = ReferenceType.SecurityScheme
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
OpenApiSecurityRequirement securityRequirements = new OpenApiSecurityRequirement()
|
|
|
|
{
|
|
|
|
{securityScheme, new string[] { }},
|
|
|
|
};
|
|
|
|
|
|
|
|
options.AddSecurityRequirement(securityRequirements);
|
2023-08-24 20:25:38 -05:00
|
|
|
});
|
2023-12-01 17:55:45 -05:00
|
|
|
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
2023-08-15 22:52:30 -05:00
|
|
|
builder.Services.AddScoped<IAttachmentsProvider, AttachmentsProvider>();
|
|
|
|
builder.Services.AddScoped<IUploadService, UploadService>();
|
|
|
|
builder.Services.AddScoped<IAzureBlobService,AzureBlobService>();
|
|
|
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
|
|
|
|
builder.Services.AddDbContext<AttachmentsDbContext>(option =>
|
|
|
|
{
|
|
|
|
option.UseInMemoryDatabase("Attachments");
|
|
|
|
});
|
|
|
|
builder.Services.Configure<FormOptions>(o =>
|
|
|
|
{
|
|
|
|
o.ValueLengthLimit = int.MaxValue;
|
|
|
|
o.MultipartBodyLengthLimit = int.MaxValue;
|
|
|
|
o.MemoryBufferThreshold = int.MaxValue;
|
|
|
|
});
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
}
|
|
|
|
|
2023-09-19 23:32:30 -05:00
|
|
|
app.UseAuthentication();
|
2023-08-15 22:52:30 -05:00
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.Run();
|