Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ services:
ASPNETCORE_ENVIRONMENT: Development
Database__DefaultConnection: "Host=postgres;Port=5432;Database=simplemodule;Username=simplemodule;Password=${POSTGRES_PASSWORD:-simplemodule}"
Database__Provider: PostgreSQL
# Set to your public URL so OpenIddict registers correct redirect URIs.
# Examples: https://app.simplemodule.dev, http://localhost:8080
OpenIddict__BaseUrl: ${APP_BASE_URL:-http://localhost:8080}
depends_on:
postgres:
condition: service_healthy
Expand Down
11 changes: 11 additions & 0 deletions framework/SimpleModule.Hosting/SimpleModuleHostExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
Expand Down Expand Up @@ -48,6 +49,15 @@ public static WebApplicationBuilder AddSimpleModuleInfrastructure(
BridgeAspireConnectionString(builder.Configuration);
options.DatabaseProvider = ValidateDatabaseConfiguration(builder.Configuration);

builder.Services.Configure<ForwardedHeadersOptions>(fhOptions =>
{
fhOptions.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
// Allow any proxy in containerized/cloud environments
fhOptions.KnownIPNetworks.Clear();
fhOptions.KnownProxies.Clear();
});

builder.Services.AddProblemDetails();
builder.Services.AddExceptionHandler<GlobalExceptionHandler>();

Expand Down Expand Up @@ -129,6 +139,7 @@ public static async Task UseSimpleModuleInfrastructure(this WebApplication app)
}
}

app.UseForwardedHeaders();
app.UseExceptionHandler();

var options = app.Services.GetRequiredService<SimpleModuleOptions>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ CancellationToken cancellationToken
{
var manager = scope.ServiceProvider.GetRequiredService<IOpenIddictApplicationManager>();

if (
await manager.FindByClientIdAsync(ClientConstants.ClientId, cancellationToken)
is not null
)
{
return;
}

LogSeedingClient(logger);

var baseUrl = configuration[ConfigKeys.OpenIddictBaseUrl] ?? ClientConstants.DefaultBaseUrl;

var descriptor = new OpenIddictApplicationDescriptor
Expand Down Expand Up @@ -97,6 +87,18 @@ is not null
}
}

var existing = await manager.FindByClientIdAsync(
ClientConstants.ClientId,
cancellationToken
);
if (existing is not null)
{
LogUpdatingClient(logger);
await manager.UpdateAsync(existing, descriptor, cancellationToken);
return;
}

LogSeedingClient(logger);
await manager.CreateAsync(descriptor, cancellationToken);
}

Expand All @@ -106,6 +108,12 @@ is not null
)]
private static partial void LogSeedingClient(ILogger logger);

[LoggerMessage(
Level = LogLevel.Information,
Message = "Updating OpenIddict client application..."
)]
private static partial void LogUpdatingClient(ILogger logger);

[LoggerMessage(
Level = LogLevel.Warning,
Message = "OpenIddict seeding skipped due to error: {ErrorMessage}"
Expand Down
3 changes: 3 additions & 0 deletions template/SimpleModule.Host/appsettings.Production.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"DefaultConnection": "Data Source=/app/data/app.db",
"Provider": "Sqlite"
},
"OpenIddict": {
"BaseUrl": "https://app.simplemodule.dev"
},
"Storage": {
"Local": {
"BasePath": "/app/storage"
Expand Down
Loading