using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using YPS.Beer.Configuration; using YPS.Beer.Data; using YPS.Beer.Models; using YPS.Beer.Services; var builder = WebApplication.CreateBuilder(args); var punkServiceConfiguration = new PunkServiceConfiguration(); builder.Configuration.GetSection(PunkServiceConfiguration.ConfigurationSection).Bind(punkServiceConfiguration); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddControllers(); builder.Services.AddHttpClient() .ConfigureHttpClient(client => client.BaseAddress = new Uri(punkServiceConfiguration.BaseUrl)); builder.Services.AddScoped(); builder.Services.AddDbContext(options => options.UseInMemoryDatabase("yps-beer")); builder.Services.AddIdentityCore() .AddEntityFrameworkStores() .AddApiEndpoints(); builder.Services.AddAuthentication(IdentityConstants.ApplicationScheme) .AddBearerToken(IdentityConstants.BearerScheme) .AddApplicationCookie(); builder.Services.AddAuthorizationBuilder(); builder.Services.AddCors(); var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); app.UseCors(cors => cors.AllowAnyHeader().AllowAnyMethod().SetIsOriginAllowed(_ => true).AllowCredentials()); } app.UseHttpsRedirection(); app.MapControllers(); app.MapIdentityApi(); app.Run();