| | 1 | | using System.Text; |
| | 2 | | using Microsoft.AspNetCore.Authentication.JwtBearer; |
| | 3 | | using Microsoft.IdentityModel.Tokens; |
| | 4 | | using WebApi.DAO; |
| | 5 | | using WebApi.Services; |
| | 6 | | using SharedObjects.Auth; |
| | 7 | |
|
| 0 | 8 | | var builder = WebApplication.CreateBuilder(args); |
| | 9 | |
|
| | 10 | | // Add services to the container. |
| | 11 | | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |
| 0 | 12 | | builder.Services.AddControllers(); |
| 0 | 13 | | builder.Services.AddEndpointsApiExplorer(); |
| 0 | 14 | | builder.Services.AddSwaggerGen(); |
| | 15 | |
|
| | 16 | | // Register the MongoDbContext |
| 0 | 17 | | builder.Services.AddSingleton<MongoDbContext>(sp => |
| 0 | 18 | | new MongoDbContext( |
| 0 | 19 | | builder.Configuration.GetConnectionString("MongoDB"), |
| 0 | 20 | | "auth_db" |
| 0 | 21 | | ) |
| 0 | 22 | | ); |
| 0 | 23 | | builder.Services.AddScoped<IUserDAO, UserDAO>(); |
| 0 | 24 | | builder.Services.AddScoped<IUserService, UserService>(); |
| | 25 | |
|
| 0 | 26 | | AuthorizationPolicies.AddAuth(builder); |
| | 27 | |
|
| 0 | 28 | | var app = builder.Build(); |
| | 29 | |
|
| | 30 | | // Configure the HTTP request pipeline. |
| 0 | 31 | | if (app.Environment.IsDevelopment()) |
| 0 | 32 | | { |
| 0 | 33 | | app.UseSwagger(); |
| 0 | 34 | | app.UseSwaggerUI(); |
| 0 | 35 | | } |
| | 36 | |
|
| 0 | 37 | | app.UseCors(x => x |
| 0 | 38 | | .AllowAnyMethod() |
| 0 | 39 | | .AllowAnyHeader() |
| 0 | 40 | | .SetIsOriginAllowed(origin => true) // allow any origin |
| 0 | 41 | | .AllowCredentials()); |
| | 42 | |
|
| 0 | 43 | | app.UseHttpsRedirection(); |
| | 44 | |
|
| 0 | 45 | | app.UseAuthentication(); |
| | 46 | |
|
| 0 | 47 | | app.UseAuthorization(); |
| | 48 | |
|
| 0 | 49 | | app.MapControllers(); |
| | 50 | |
|
| 0 | 51 | | app.Run(); |