| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System.Text;
- using Common.Global;
- using Database.Database;
- using Esim.Apis.Business;
- using Microsoft.AspNetCore.Authentication.JwtBearer;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.IdentityModel.Tokens;
- var builder = WebApplication.CreateBuilder(args);
- // Set global configuration for use by singletons like ConfigManager
- GlobalConfig.Configuration = builder.Configuration;
- // Add services to the container.
- builder.Services.AddControllersWithViews();
- // Add DbContext with Oracle provider
- var connectionString = builder.Configuration.GetSection("Connection").Value;
- builder.Services.AddDbContext<ModelContext>(options =>
- options.UseOracle(connectionString));
- // Add Business Services
- builder.Services.AddScoped<IUserBusiness, UserBusinessImpl>();
- // Configure JWT Authentication
- var jwtKey = builder.Configuration["Jwt:Key"] ?? "EsimLaoSecretKey12345678901234567890";
- var jwtIssuer = builder.Configuration["Jwt:Issuer"] ?? "EsimLao";
- var jwtAudience = builder.Configuration["Jwt:Audience"] ?? "EsimLaoClient";
- builder.Services.AddAuthentication(options =>
- {
- options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
- options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
- })
- .AddJwtBearer(options =>
- {
- options.TokenValidationParameters = new TokenValidationParameters
- {
- ValidateIssuer = true,
- ValidateAudience = true,
- ValidateLifetime = true,
- ValidateIssuerSigningKey = true,
- ValidIssuer = jwtIssuer,
- ValidAudience = jwtAudience,
- IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtKey))
- };
- });
- // Add Swagger for API documentation
- builder.Services.AddEndpointsApiExplorer();
- builder.Services.AddSwaggerGen();
- var app = builder.Build();
- app.UseSwagger();
- app.UseSwaggerUI();
- // Configure the HTTP request pipeline.
- //if (app.Environment.IsDevelopment())
- //{
- // app.UseSwagger();
- // app.UseSwaggerUI();
- //}
- //else
- //{
- // app.UseExceptionHandler("/Home/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.UseHttpsRedirection();
- app.UseRouting();
- app.UseAuthentication();
- app.UseAuthorization();
- app.MapStaticAssets();
- app.MapControllerRoute(
- name: "default",
- pattern: "{controller=Home}/{action=Index}/{id?}")
- .WithStaticAssets();
- app.MapControllers();
- app.Run();
|