mirror of
https://github.com/damienbod/AspNetCoreIdentityFido2Mfa.git
synced 2025-10-25 15:19:18 +00:00
71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
using AspNetCoreIdentityFido2Passwordless.Data;
|
|
using Fido2Identity;
|
|
using Fido2NetLib;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'ApplicationDbContextConnection' not found.");
|
|
|
|
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
|
options.UseSqlServer(connectionString));
|
|
|
|
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
|
|
.AddEntityFrameworkStores<ApplicationDbContext>()
|
|
.AddTokenProvider<Fido2UserTwoFactorTokenProvider>("FIDO2");
|
|
|
|
builder.Services.Configure<CookiePolicyOptions>(options =>
|
|
{
|
|
options.Secure = CookieSecurePolicy.Always;
|
|
options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
|
|
//options.OnAppendCookie = cookieContext =>
|
|
// CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
|
|
//options.OnDeleteCookie = cookieContext =>
|
|
// CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
|
|
});
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
builder.Services.AddRazorPages();
|
|
|
|
builder.Services.Configure<Fido2Configuration>(builder.Configuration.GetSection("fido2"));
|
|
builder.Services.AddScoped<Fido2Store>();
|
|
// Adds a default in-memory implementation of IDistributedCache.
|
|
builder.Services.AddDistributedMemoryCache();
|
|
builder.Services.AddSession(options =>
|
|
{
|
|
options.IdleTimeout = TimeSpan.FromMinutes(2);
|
|
options.Cookie.HttpOnly = true;
|
|
options.Cookie.SameSite = SameSiteMode.None;
|
|
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
|
|
});
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseMigrationsEndPoint();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Error");
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.MapStaticAssets();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseSession();
|
|
|
|
app.MapRazorPages();
|
|
app.MapControllers();
|
|
|
|
app.Run();
|