forked from Kareadita/Kavita
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the ability to change the JWT key on runtime. (Kareadita#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
- Loading branch information
1 parent
98e8b72
commit 03b49a5
Showing
8 changed files
with
67 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.