feat: Add authentication configuration with OpenID Connect and update appsettings #4
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user