refactor(worker): OnlineTokenStore zu DpapiTokenStore verallgemeinert
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
using System.Runtime.Versioning;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using ClaudeDo.Data;
|
||||
|
||||
namespace ClaudeDo.Worker.Online;
|
||||
|
||||
/// <summary>
|
||||
/// Persists the Zitadel refresh token encrypted with DPAPI (CurrentUser scope).
|
||||
/// Windows-only; the file lives at ~/.claudeDo/online-inbox.token.
|
||||
/// </summary>
|
||||
[SupportedOSPlatform("windows")]
|
||||
public sealed class OnlineTokenStore
|
||||
{
|
||||
private readonly string _tokenPath;
|
||||
|
||||
public OnlineTokenStore()
|
||||
: this(Path.Combine(Paths.AppDataRoot(), "online-inbox.token")) { }
|
||||
|
||||
internal OnlineTokenStore(string tokenPath)
|
||||
{
|
||||
_tokenPath = tokenPath;
|
||||
}
|
||||
|
||||
public void Save(string refreshToken)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrEmpty(refreshToken);
|
||||
var plain = Encoding.UTF8.GetBytes(refreshToken);
|
||||
var cipher = ProtectedData.Protect(plain, null, DataProtectionScope.CurrentUser);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(_tokenPath)!);
|
||||
File.WriteAllBytes(_tokenPath, cipher);
|
||||
}
|
||||
|
||||
public string? Read()
|
||||
{
|
||||
if (!File.Exists(_tokenPath)) return null;
|
||||
try
|
||||
{
|
||||
var cipher = File.ReadAllBytes(_tokenPath);
|
||||
var plain = ProtectedData.Unprotect(cipher, null, DataProtectionScope.CurrentUser);
|
||||
return Encoding.UTF8.GetString(plain);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (File.Exists(_tokenPath))
|
||||
File.Delete(_tokenPath);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace ClaudeDo.Worker.Online;
|
||||
public sealed class ZitadelAuthProvider : IOnlineAuthProvider
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly OnlineTokenStore _tokenStore;
|
||||
private readonly DpapiTokenStore _tokenStore;
|
||||
private readonly OnlineInboxConfig _config;
|
||||
private readonly ILogger<ZitadelAuthProvider> _logger;
|
||||
|
||||
@@ -29,12 +29,12 @@ public sealed class ZitadelAuthProvider : IOnlineAuthProvider
|
||||
|
||||
public ZitadelAuthProvider(
|
||||
IHttpClientFactory httpClientFactory,
|
||||
OnlineTokenStore tokenStore,
|
||||
OnlineRefreshTokenStore tokenStore,
|
||||
OnlineInboxConfig config,
|
||||
ILogger<ZitadelAuthProvider> logger)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_tokenStore = tokenStore;
|
||||
_tokenStore = tokenStore.Store;
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user