Skip to content

Commit

Permalink
Add cert auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Galloway committed Sep 18, 2024
1 parent ddf463e commit f919d56
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
28 changes: 25 additions & 3 deletions Mostlylucid/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
using System.Security.Cryptography.X509Certificates;
using Mostlylucid.Services;
using OpenTelemetry.Metrics;
using Serilog.Debugging;

try
{
var builder = WebApplication.CreateBuilder(args);
var config = builder.Configuration;
config.AddEnvironmentVariables();
var certExists = File.Exists("mostlylucid.pfx");
var certPassword = config["CertPassword"];

builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(8080); // HTTP endpoint


// HTTPS endpoint using SSL certificate
options.ListenAnyIP(7240, listenOptions =>
{
if (certExists)
{
var certificate = new X509Certificate2("mostlylucid.pfx", certPassword);
listenOptions.UseHttps(options => options.ServerCertificate = certificate);
}
else
//Local development without certificate.
listenOptions.UseHttps();

});
});;
builder.Host.UseSerilog((context, configuration) =>
{
configuration.ReadFrom.Configuration(context.Configuration);
Expand All @@ -20,8 +42,8 @@
.AspNetCoreRequests()
.TraceToSharedLogger();

var config = builder.Configuration;
builder.Configuration.AddEnvironmentVariables();


builder.Configure<AnalyticsSettings>();
var auth = builder.Configure<AuthSettings>();
var translateServiceConfig = builder.Configure<TranslateServiceConfig>();
Expand Down
5 changes: 3 additions & 2 deletions Mostlylucid/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7240;http://localhost:5118",
// "applicationUrl": "https://localhost:7240;http://localhost:5118",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Development",
"CertPassword": "melkweg26"
}
},
"IIS Express": {
Expand Down
4 changes: 2 additions & 2 deletions Mostlylucid/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=<database>;port=5432;Username=<username>;Password=<password>"
},

}
,
"Markdown":
{
"MarkdownPath": "Markdown",
Expand Down

0 comments on commit f919d56

Please sign in to comment.