99 lines
3.0 KiB
C#
99 lines
3.0 KiB
C#
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Authentication.Google;
|
|
using Microsoft.AspNetCore.Authentication.MicrosoftAccount;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
|
using Microsoft.Extensions.Options;
|
|
using Stripe;
|
|
using Stripe.Forwarding;
|
|
using System.Globalization;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// 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;
|
|
options.DefaultChallengeScheme = MicrosoftAccountDefaults.AuthenticationScheme;
|
|
})
|
|
.AddCookie(options =>
|
|
{
|
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
|
|
options.SlidingExpiration = true;
|
|
options.AccessDeniedPath = "/Forbidden/";
|
|
})
|
|
.AddGoogle(googleOptions =>
|
|
{
|
|
googleOptions.ClientId = config["Authentication:Google:ClientId"];
|
|
googleOptions.ClientSecret = config["Authentication:Google:ClientSecret"];
|
|
})
|
|
.AddMicrosoftAccount(microsoftOptions =>
|
|
{
|
|
microsoftOptions.ClientId = config["Authentication:Microsoft:ClientId"];
|
|
//microsoftOptions.ClientSecret = "2a7cb1bd-037a-49fa-9e5e-2b2655431af9";
|
|
microsoftOptions.ClientSecret = config["Authentication:Microsoft:ClientSecret"];
|
|
})
|
|
;
|
|
|
|
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();
|
|
|
|
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.UseRequestLocalization();
|
|
|
|
app.Run();
|