summaryrefslogtreecommitdiff
path: root/VPNAuth.Server/Config.cs
diff options
context:
space:
mode:
authorTim <contact@bytim.eu>2025-04-18 12:25:59 +0200
committerTim <contact@bytim.eu>2025-04-18 12:25:59 +0200
commit4b2ad030fa381662f4b0c2464e97b0d2c5f6a716 (patch)
treedcc6af3136764322bd779110dcedd35e293d583c /VPNAuth.Server/Config.cs
downloadVPNAuth-4b2ad030fa381662f4b0c2464e97b0d2c5f6a716.tar.xz
VPNAuth-4b2ad030fa381662f4b0c2464e97b0d2c5f6a716.zip
Initial commit
Diffstat (limited to 'VPNAuth.Server/Config.cs')
-rw-r--r--VPNAuth.Server/Config.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/VPNAuth.Server/Config.cs b/VPNAuth.Server/Config.cs
new file mode 100644
index 0000000..84b01ef
--- /dev/null
+++ b/VPNAuth.Server/Config.cs
@@ -0,0 +1,49 @@
+using System.Text.Json;
+
+namespace VPNAuth.Server;
+
+public class ConfigUser
+{
+ public string? Username { get; set; }
+ public List<string>? Ips { get; set; }
+
+ public string? Sub { get; set; }
+ public string? Name { get; set; }
+ public string? GivenName { get; set; }
+ public string? FamilyName { get; set; }
+ public string? PreferredUsername { get; set; }
+ public string? Email { get; set; }
+ public string? Picture { get; set; }
+}
+
+public class ConfigApp
+{
+ public string? ClientId { get; set; }
+ public string? RedirectUri { get; set; }
+ public string? Secret { get; set; }
+}
+
+public class Config
+{
+ public List<ConfigUser>? Users { get; set; }
+ public List<ConfigApp>? Apps { get; set; }
+
+ public ConfigApp? FindApp(string clientId)
+ => Apps?.Find(app => app.ClientId == clientId);
+
+ private static string _filePath = "./config.json";
+
+ public static void CreateIfNotExists()
+ {
+ if (File.Exists(_filePath)) return;
+
+ File.Create(_filePath);
+ File.WriteAllText(_filePath, JsonSerializer.Serialize(new Config
+ {
+ Users = []
+ }));
+ }
+
+ public static Config Read()
+ => JsonSerializer.Deserialize<Config>(File.ReadAllText(_filePath))!;
+}