c#
using dotenv.net;
using Microsoft.AspNetCore.Authentication.Cookies;
var envVars = DotEnv.Read();
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages(options =>
{
options.Conventions.AuthorizePage("/");
});
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "Authentik";
}).AddCookie(options =>
{
options.LoginPath = "/auth/login";
options.LogoutPath = "/auth/logout";
}).AddOAuth("Authentik", options =>
{
options.AuthorizationEndpoint = envVars["AUTHORIZATION_ENDPOINT"];
options.TokenEndpoint = envVars["TOKEN_ENDPOINT"];
options.UserInformationEndpoint = envVars["USER_INFORMATION_ENDPOINT"];
options.ClientId = envVars["CLIENT_ID"];
options.ClientSecret = envVars["CLIENT_SECRET"];
options.ClaimsIssuer = envVars["CLAIMS_ISSUER"];
options.CallbackPath = "/auth/callback";
});
var app = builder.Build();
app.UseAuthentication();
app.MapRazorPages();
app.Run();