89 lines
2.8 KiB
C#
89 lines
2.8 KiB
C#
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<CookieAuthenticationOptions> ( 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<IRolAPI, RolAPI> ();
|
|
builder.Services.AddScoped<IPaisAPI, PaisAPI> ();
|
|
builder.Services.AddScoped<IPagoAPI, PagoAPI> ();
|
|
builder.Services.AddScoped<IBancoAPI, BancoAPI> ();
|
|
builder.Services.AddScoped<IMonedaAPI, MonedaAPI> ();
|
|
builder.Services.AddScoped<IClienteAPI, ClienteAPI> ();
|
|
builder.Services.AddScoped<IFacturaAPI, FacturaAPI> ();
|
|
builder.Services.AddScoped<IUsuarioAPI, UsuarioAPI> ();
|
|
builder.Services.AddScoped<ITelefonoAPI, TelefonoAPI> ();
|
|
builder.Services.AddScoped<IRolDeUsuarioAPI, RolDeUsuarioAPI> ();
|
|
builder.Services.AddScoped<ITipoTelefonoAPI, TipoTelefonoAPI> ();
|
|
builder.Services.AddScoped<ITipoDocumentoAPI, TipoDocumentoAPI> ();
|
|
builder.Services.AddScoped<ITipoPagoAPI, TipoPagoAPI> ();
|
|
builder.Services.AddScoped<ITipoIdentificacionAPI, TipoIdentificacionAPI> ();
|
|
builder.Services.AddScoped<IPagoContieneFacturaAPI, PagoContieneFacturaAPI> ();
|
|
|
|
#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 ();
|