129 lines
3.7 KiB
C#
129 lines
3.7 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using TIAM.Entities.TransferDestinations;
|
|
using TIAM.Database.DbContexts;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using System.Text;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using Microsoft.OpenApi.Models;
|
|
using TIAMWebApp.Shared.Application.Models;
|
|
using TIAM.Database.DataLayers.Users;
|
|
using TIAM.Database.DataLayers.TransferDestinations;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllersWithViews();
|
|
builder.Services.AddRazorPages();
|
|
//builder.Services.AddDbContext<TransferDestinationDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DeveloperDbConnection")));;
|
|
builder.Services.AddScoped<UserDal>();
|
|
builder.Services.AddScoped<AdminDal>();
|
|
builder.Services.AddScoped<AuctionDal>();
|
|
builder.Services.AddScoped<TransferDestinationDal>();
|
|
|
|
builder.Services.AddSwaggerGen(swagger =>
|
|
{
|
|
swagger.SwaggerDoc("v1",
|
|
new OpenApiInfo
|
|
{
|
|
Title = "API Title",
|
|
Version = "V1",
|
|
Description = "API Description"
|
|
});
|
|
|
|
var securitySchema = new OpenApiSecurityScheme
|
|
{
|
|
Description = "Authorization header using the Bearer scheme. Example \"Authorization: Bearer {token}\"",
|
|
Name = "Authorization",
|
|
In = ParameterLocation.Header,
|
|
Type = SecuritySchemeType.Http,
|
|
Scheme = "Bearer",
|
|
Reference = new OpenApiReference
|
|
{
|
|
Type = ReferenceType.SecurityScheme,
|
|
Id = "Bearer"
|
|
}
|
|
};
|
|
swagger.AddSecurityDefinition(securitySchema.Reference.Id, securitySchema);
|
|
swagger.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
{
|
|
{securitySchema,Array.Empty<string>() }
|
|
});
|
|
});
|
|
|
|
builder.Services.AddAuthentication(f =>
|
|
{
|
|
f.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
f.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
}).AddJwtBearer(k =>
|
|
{
|
|
var Key = Encoding.UTF8.GetBytes(builder.Configuration["JWT:Key"]);
|
|
k.SaveToken = true;
|
|
k.TokenValidationParameters = new TokenValidationParameters
|
|
{
|
|
ValidateIssuer = true,
|
|
ValidateAudience = true,
|
|
ValidateLifetime = true,
|
|
ValidateIssuerSigningKey = true,
|
|
ValidIssuer = builder.Configuration["JWT:Issuer"],
|
|
ValidAudience = builder.Configuration["JWT:Audience"],
|
|
IssuerSigningKey = new SymmetricSecurityKey(Key),
|
|
ClockSkew = TimeSpan.Zero
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
builder.Services.ConfigureApplicationCookie(options =>
|
|
{
|
|
options.Cookie.HttpOnly = false;
|
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
|
|
options.LoginPath = "/Login";
|
|
options.SlidingExpiration = true;
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseWebAssemblyDebugging();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Error");
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
|
|
});
|
|
|
|
|
|
//app.UseHttpsRedirection();
|
|
|
|
app.UseBlazorFrameworkFiles();
|
|
app.UseStaticFiles();
|
|
|
|
app.UseAuthentication();
|
|
app.UseRouting();
|
|
app.UseAuthorization();
|
|
|
|
|
|
app.MapRazorPages();
|
|
app.MapControllers();
|
|
app.MapFallbackToFile("index.html");
|
|
app.Run();
|