generated from ricardo/MVCLogin
126 lines
3.8 KiB
C#
126 lines
3.8 KiB
C#
using Blinks.LogConfig;
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Authentication.Google;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
|
using Microsoft.Extensions.Options;
|
|
using Postall.Domain.Services;
|
|
using Postall.Infra.Services;
|
|
using Serilog;
|
|
using Serilog.Sinks.Grafana.Loki;
|
|
using Stripe;
|
|
using Stripe.Forwarding;
|
|
using System.Globalization;
|
|
using System.Security.Policy;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
//var credentials = new BasicAuthCredentials("http://192.168.0.82:3100");
|
|
//var credentials = new LogCredentials("http://192.168.0.82:3100");
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
.MinimumLevel.Information()
|
|
.Enrich.FromLogContext()
|
|
.Enrich.WithProperty("app", "blinks")
|
|
.WriteTo.Console()
|
|
.WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day)
|
|
.WriteTo.GrafanaLoki(
|
|
uri: "http://192.168.0.82:3100",
|
|
propertiesAsLabels: new List<string> { "app", "blinks" },
|
|
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug
|
|
)
|
|
.CreateLogger();
|
|
|
|
builder.Host.UseSerilog();
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddControllersWithViews();
|
|
|
|
var config = builder.Configuration;
|
|
|
|
//builder.Services.AddAuthentication()
|
|
builder.Services.AddAuthentication(
|
|
options =>
|
|
{
|
|
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
})
|
|
.AddCookie(options =>
|
|
{
|
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
|
|
options.SlidingExpiration = true;
|
|
options.AccessDeniedPath = "/Forbidden/";
|
|
})
|
|
.AddGoogle(googleOptions =>
|
|
{
|
|
googleOptions.ClientId = builder.Configuration.GetSection("Authentication:Google:AppId").Value;
|
|
googleOptions.ClientSecret = builder.Configuration.GetSection("Authentication:Google:AppSecret").Value;
|
|
googleOptions.CallbackPath = "/signin-google";
|
|
})
|
|
.AddFacebook(options =>
|
|
{
|
|
options.AppId = builder.Configuration.GetSection("Authentication:Facebook:AppId").Value;
|
|
options.AppSecret = builder.Configuration.GetSection("Authentication:Facebook:AppSecret").Value;
|
|
});
|
|
;
|
|
|
|
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
|
|
|
|
builder.Services.AddMvc()
|
|
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
|
|
.AddDataAnnotationsLocalization();
|
|
|
|
builder.Services.Configure<RequestLocalizationOptions>(options =>
|
|
{
|
|
var supportedCultures = new List<CultureInfo>
|
|
{
|
|
new CultureInfo("pt-BR"),
|
|
new CultureInfo("en")
|
|
};
|
|
|
|
options.DefaultRequestCulture = new RequestCulture("pt-BR");
|
|
options.SupportedCultures = supportedCultures;
|
|
options.SupportedUICultures = supportedCultures;
|
|
});
|
|
|
|
StripeConfiguration.ApiKey = builder.Configuration["Stripe:SecretKey"];
|
|
builder.Services.AddControllersWithViews();
|
|
builder.Services.AddHttpClient();
|
|
builder.Services.AddSerilog();
|
|
|
|
builder.Services.AddScoped<IFacebookServices, FacebookTokenService>();
|
|
|
|
var app = builder.Build();
|
|
|
|
var locOptions = app.Services.GetService<IOptions<RequestLocalizationOptions>>();
|
|
app.UseRequestLocalization(locOptions.Value);
|
|
|
|
app.UseMiddleware<RequestLocalizationMiddleware>();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
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.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
app.UseSerilogRequestLogging();
|
|
|
|
app.UseRequestLocalization();
|
|
|
|
app.Run();
|