2023-07-25 02:22:18 +00:00
|
|
|
using BotSharp.Abstraction.Users;
|
2023-05-27 01:58:31 +00:00
|
|
|
using BotSharp.Core;
|
2023-12-19 13:16:43 +00:00
|
|
|
using BotSharp.OpenAPI;
|
2023-07-25 02:22:18 +00:00
|
|
|
using BotSharp.Core.Users.Services;
|
2023-11-29 23:23:14 +00:00
|
|
|
using BotSharp.Logger;
|
2023-11-27 02:04:05 +00:00
|
|
|
using BotSharp.Plugin.ChatHub;
|
2023-12-20 14:12:59 +00:00
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
|
using System.Text;
|
2024-01-09 00:40:52 +00:00
|
|
|
using Serilog;
|
2023-05-27 01:58:31 +00:00
|
|
|
|
2023-05-26 01:36:15 +00:00
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
2024-01-10 14:18:59 +00:00
|
|
|
var loggerConfig = new LoggerConfiguration();
|
|
|
|
|
Log.Logger = loggerConfig
|
|
|
|
|
#if DEBUG
|
2024-01-09 00:40:52 +00:00
|
|
|
.MinimumLevel.Debug()
|
2024-01-10 14:18:59 +00:00
|
|
|
#else
|
|
|
|
|
.MinimumLevel.Warning()
|
|
|
|
|
#endif
|
2024-01-09 00:40:52 +00:00
|
|
|
.WriteTo.Console()
|
|
|
|
|
.WriteTo.File("logs/log-.txt", rollingInterval: RollingInterval.Day)
|
|
|
|
|
.CreateLogger();
|
2024-01-10 14:18:59 +00:00
|
|
|
builder.Host.UseSerilog();
|
2024-01-09 00:40:52 +00:00
|
|
|
|
2023-07-25 02:22:18 +00:00
|
|
|
builder.Services.AddScoped<IUserIdentity, UserIdentity>();
|
2023-12-20 14:12:59 +00:00
|
|
|
// Add bearer authentication
|
|
|
|
|
builder.Services.AddAuthentication(options =>
|
|
|
|
|
{
|
|
|
|
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
}).AddJwtBearer(o =>
|
|
|
|
|
{
|
|
|
|
|
o.TokenValidationParameters = new TokenValidationParameters
|
|
|
|
|
{
|
|
|
|
|
ValidIssuer = builder.Configuration["Jwt:Issuer"],
|
|
|
|
|
ValidAudience = builder.Configuration["Jwt:Audience"],
|
|
|
|
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])),
|
|
|
|
|
ValidateIssuer = true,
|
|
|
|
|
ValidateAudience = true,
|
|
|
|
|
ValidateLifetime = false,
|
|
|
|
|
ValidateIssuerSigningKey = true
|
|
|
|
|
};
|
|
|
|
|
});
|
2023-07-25 02:22:18 +00:00
|
|
|
|
2023-05-27 01:58:31 +00:00
|
|
|
// Add BotSharp
|
2023-11-29 23:23:14 +00:00
|
|
|
builder.Services.AddBotSharpCore(builder.Configuration);
|
2023-12-19 13:16:43 +00:00
|
|
|
builder.Services.AddBotSharpOpenAPI(builder.Configuration);
|
2023-11-29 23:23:14 +00:00
|
|
|
builder.Services.AddBotSharpLogger(builder.Configuration);
|
2023-08-14 18:16:35 +00:00
|
|
|
|
2023-06-03 02:07:30 +00:00
|
|
|
builder.Services.AddCors(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AddPolicy("MyCorsPolicy",
|
2024-01-10 14:18:59 +00:00
|
|
|
builder => builder.WithOrigins("http://localhost:5015",
|
|
|
|
|
"http://localhost:5500",
|
2024-01-09 00:40:52 +00:00
|
|
|
"https://botsharp.scisharpstack.org",
|
|
|
|
|
"https://chat.scisharpstack.org")
|
2023-06-03 02:07:30 +00:00
|
|
|
.AllowAnyMethod()
|
2023-11-27 02:04:05 +00:00
|
|
|
.AllowAnyHeader()
|
|
|
|
|
.AllowCredentials());
|
2023-06-03 02:07:30 +00:00
|
|
|
});
|
|
|
|
|
|
2023-11-27 02:04:05 +00:00
|
|
|
builder.Services.AddSignalR();
|
|
|
|
|
|
2023-05-26 01:36:15 +00:00
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
2023-11-28 03:19:07 +00:00
|
|
|
app.MapHub<SignalRHub>("/chatHub");
|
2024-01-10 14:18:59 +00:00
|
|
|
app.UseChatHub();
|
2023-11-28 03:19:07 +00:00
|
|
|
|
2023-06-11 23:46:02 +00:00
|
|
|
app.UseAuthentication();
|
2023-05-26 01:36:15 +00:00
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
2023-05-27 01:58:31 +00:00
|
|
|
// Use BotSharp
|
|
|
|
|
app.UseBotSharp();
|
2024-01-10 14:18:59 +00:00
|
|
|
app.UseBotSharpOpenAPI();
|
|
|
|
|
app.UseBotSharpUI();
|
2023-05-27 01:58:31 +00:00
|
|
|
|
2023-06-03 02:07:30 +00:00
|
|
|
app.UseCors("MyCorsPolicy");
|
|
|
|
|
|
2023-05-26 01:36:15 +00:00
|
|
|
app.Run();
|