|
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
|
|
using System.Security.Claims;
|
|
|
|
using Autofac;
|
|
|
|
using Autofac.Extensions.DependencyInjection;
|
|
|
|
using DS.Module.AutofacModule;
|
|
|
|
using DS.Module.HkOpenApi;
|
|
|
|
using DS.Module.SqlSugar;
|
|
|
|
using DS.WMS.OpenApi;
|
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
//Autofac注入
|
|
|
|
builder.Host
|
|
|
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
|
|
|
.ConfigureContainer<ContainerBuilder>(builder => { builder.RegisterModule(new AutofacModuleRegister()); });
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddAppWebInstal();
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
builder.Services.AddSqlsugarInstall();
|
|
|
|
builder.Services.AddHKModuleInstall();//海康服务
|
|
|
|
// 以下是加入了JWT身份认证
|
|
|
|
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
|
|
|
|
{
|
|
|
|
options.Authority = "http://localhost:3005";
|
|
|
|
options.RequireHttpsMetadata = false;
|
|
|
|
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
|
|
|
|
{
|
|
|
|
ValidateAudience = false
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI(c =>
|
|
|
|
{
|
|
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "OPEN API V1");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// app.UseHttpsRedirection();
|
|
|
|
app.UseAuthentication();
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
|
|
app.Run();
|