blob: 84b01efa01029c25aa1ca21f6d3c6dc129df80ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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))!;
}
|