From 4b2ad030fa381662f4b0c2464e97b0d2c5f6a716 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 18 Apr 2025 12:25:59 +0200 Subject: Initial commit --- VPNAuth.Server/Config.cs | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 VPNAuth.Server/Config.cs (limited to 'VPNAuth.Server/Config.cs') 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? 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? Users { get; set; } + public List? 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(File.ReadAllText(_filePath))!; +} -- cgit v1.2.3