Skip to content

Commit 4d4a1e5

Browse files
myieyeclaude
andcommitted
fix(auth): move FwLiteWeb MSAL cache to a stable per-user location
The cache was pinned to AppContext.BaseDirectory (the binary directory). Platform.Bible extracts each extension version to a versioned cache dir (~/.platform.bible/cache/extensions/<name>_<version>/), so a binary-relative cache is orphaned on every update — the user is silently logged out per update — and a cache/ tree is also wipeable by cache cleaning. Store msal.json under LocalApplicationData/SIL/FwLiteWeb instead (resolves to %LOCALAPPDATA% on Windows, ~/.local/share on Linux, ~/Library/Application Support on macOS), mirroring FwLiteMaui's stable-per-user pattern. Create the directory up front since MsalCacheHelper needs a fully-qualified path with an existing parent. Best-effort migrate an existing binary-relative msal.json so standalone FwLiteWeb users are not logged out by this change. Refs #2306 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 267964d commit 4d4a1e5

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

backend/FwLite/FwLiteWeb/FwLiteWebServer.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,32 @@ public static WebApplication SetupAppServer(WebApplicationOptions options, Actio
4343
..config.LexboxServers,
4444
new(new("https://lexbox.org"), "Lexbox")
4545
]);
46-
//pin the MSAL cache to the binary directory, not the current working directory — Path.GetFullPath
47-
//in the AuthConfig default would otherwise depend on CWD at config-instantiation time.
4846
builder.Services.PostConfigure<AuthConfig>(config =>
49-
config.CacheFileName = Path.Combine(AppContext.BaseDirectory, "msal.json"));
47+
{
48+
//stable per-user cache location. A binary-relative path is orphaned under Platform.Bible, which
49+
//extracts each extension version to a versioned cache dir, so every update would log the user out.
50+
var cacheDir = Path.Combine(
51+
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
52+
"SIL",
53+
"FwLiteWeb");
54+
Directory.CreateDirectory(cacheDir);
55+
var cacheFile = Path.Combine(cacheDir, "msal.json");
56+
57+
var legacyCacheFile = Path.Combine(AppContext.BaseDirectory, "msal.json");
58+
if (!File.Exists(cacheFile) && File.Exists(legacyCacheFile))
59+
{
60+
try
61+
{
62+
File.Copy(legacyCacheFile, cacheFile);
63+
}
64+
catch
65+
{
66+
//a failed migration just means one re-login; never break startup over it.
67+
}
68+
}
69+
70+
config.CacheFileName = cacheFile;
71+
});
5072
builder.Services.Configure<FwLiteConfig>(config =>
5173
{
5274
config.AppVersion = VersionHelper.DisplayVersion(typeof(FwLiteWebServer).Assembly);

0 commit comments

Comments
 (0)