Implemented the ability to change the JWT key on runtime. (#217)
* 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
This commit is contained in:
parent
98e8b7297b
commit
03b49a5268
8 changed files with 67 additions and 24 deletions
|
|
@ -0,0 +1,47 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
|
||||
<PackageReference Include="Sentry" Version="3.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
@ -16,9 +17,6 @@
|
|||
<Reference Include="JetBrains.ReSharper.TestRunner.Merged, Version=1.3.1.55, Culture=neutral, PublicKeyToken=5c492ec4f3eccde3">
|
||||
<HintPath>D:\Program Files\JetBrains\JetBrains Rider 2020.3.2\lib\ReSharperHost\TestRunner\netcoreapp2.0\JetBrains.ReSharper.TestRunner.Merged.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<HintPath>..\..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.5\Microsoft.Win32.Registry.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue