feat: Add authentication configuration with OpenID Connect and update appsettings #4

This commit is contained in:
Marek Lesko
2025-07-27 16:30:17 +00:00
parent 813b7ac9aa
commit b991f009c7
3 changed files with 37 additions and 0 deletions

View File

@@ -15,6 +15,28 @@ namespace Api
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
var pocketId = builder.Configuration.GetSection("Authentication:PocketId");
options.Authority = pocketId["Authority"];
options.ClientId = pocketId["ClientId"];
options.ClientSecret = pocketId["ClientSecret"];
options.CallbackPath = pocketId["CallbackPath"];
options.ResponseType = "code";
options.SaveTokens = true;
options.Scope.Clear();
var scopes = pocketId["Scopes"] ?? "openid";
foreach (var scope in scopes.Split(' '))
{
options.Scope.Add(scope);
}
});
builder.Services.AddControllers();
// Add DbContext with SQL Server
builder.Services.AddDbContext<AppDbContext>(options =>
@@ -34,6 +56,9 @@ namespace Api
app.UseHttpsRedirection();
}
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();