API Key hinterlegt

This commit is contained in:
2025-02-21 11:56:47 +01:00
parent 1ad0ea4d29
commit 1f03123f2e
2 changed files with 15 additions and 0 deletions

View File

@@ -248,6 +248,8 @@
<!-- <> <> <> Appsettings <> <> <> -->
<appSettings>
<add key="AdminServiceIPAddress" value="::1" />
<add key="AdminServiceAPIKey" value="HasteGedachteWa" />
<add key="SendMailOnError" value="false" />
<add key="SmptServer" value="mail.ownsoft.de" />
<add key="SmtpUser" value="bewoplaner.support@ownsoft.de" />

View File

@@ -29,6 +29,19 @@ namespace BeWo.Service.ServiceBehavior
throw new UnauthorizedAccessException($"Zugriff verweigert. Remote IP ({remoteIP ?? "Unbekannt"}) ist nicht erlaubt.");
}
// Hole erlaubten API Key aus den appSettings
string allowedApikey = ConfigurationManager.AppSettings["AdminServiceIPAddress"];
// Extrahiert den API Key von Remote
var prop = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
var remoteApikey = prop?.Headers["AdminServiceAPIKey"];
// Vergleicht die API Keys
if(remoteApikey == null || !string.Equals(remoteApikey, allowedApikey, StringComparison.Ordinal))
{
throw new UnauthorizedAccessException($"Zugriff verweigert. API Key ({remoteApikey ?? "Unbekannt"}) ist nicht erlaubt.");
}
return null; // Keine Zustandsinformationen erforderlich
}