using CuentasCobrar.UI.Services.Interfaces; using CuentasCobrar.UI.Services.Repositories; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc.Authorization; using Microsoft.Identity.Web; using Microsoft.Identity.Web.UI; var builder = WebApplication.CreateBuilder ( args ); // Autenticacion con Azure AD builder.Services.AddAuthentication ( OpenIdConnectDefaults.AuthenticationScheme ) .AddMicrosoftIdentityWebApp ( builder.Configuration.GetSection ( "AzureAd" ) ); builder.Services.AddControllersWithViews ( options => { var policy = new AuthorizationPolicyBuilder () .RequireAuthenticatedUser () .Build (); options.Filters.Add ( new AuthorizeFilter ( policy ) ); } ); builder.Services.Configure ( options => { options.LoginPath = new PathString ( "/Home/Index" ); } ); builder.Services.AddMvc (); builder.Services.AddRazorPages () .AddMvcOptions ( options => { var policy = new AuthorizationPolicyBuilder () .RequireAuthenticatedUser () .Build (); options.Filters.Add ( new AuthorizeFilter ( policy ) ); } ).AddMicrosoftIdentityUI (); #region Inyeccion de dependencias builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); builder.Services.AddScoped (); #endregion var app = builder.Build (); app.UseRequestLocalization ( new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture ( "en-US" ) } ); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment ()) { app.UseExceptionHandler ( "/Home/Error" ); } app.UseHttpsRedirection (); app.UseStaticFiles (); app.UseRouting (); app.UseAuthentication (); app.UseAuthorization (); app.MapControllerRoute ( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}" ); app.MapRazorPages (); app.Run ();