mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-04 14:14:39 -04:00
* Implemented the ability to change the JWT key on runtime. * Added .7z file extension support * Cleanup * Added Feathub link * Code cleanup * Fixed up a build issue on CI
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace Kavita.Common
|
|
{
|
|
public static class Configuration
|
|
{
|
|
|
|
public static bool CheckIfJwtTokenSet(string filePath)
|
|
{
|
|
try {
|
|
var json = File.ReadAllText(filePath);
|
|
var jsonObj = JsonSerializer.Deserialize<dynamic>(json);
|
|
const string key = "TokenKey";
|
|
|
|
JsonElement? tokenElement = null;
|
|
if (jsonObj?.TryGetProperty(key, out tokenElement))
|
|
{
|
|
return tokenElement?.GetString() != "super secret unguessable key";
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
catch (Exception ex) {
|
|
Console.WriteLine("Error writing app settings: " + ex.Message);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static bool UpdateJwtToken(string filePath, string token)
|
|
{
|
|
try
|
|
{
|
|
var json = File.ReadAllText(filePath).Replace("super secret unguessable key", token);
|
|
File.WriteAllText(filePath, json);
|
|
return true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |