OAuth session persists via DPAPI; sign-in lives in the Start Stream dialog; add xUnit test project (6 passing)

This commit is contained in:
2026-08-06 09:38:35 -07:00
parent 8f0ecd3796
commit 4afe11e718
15 changed files with 432 additions and 67 deletions
+14 -2
View File
@@ -19,14 +19,24 @@ public class YouTubeAuthService
private readonly string _clientId;
private readonly string _clientSecret;
private readonly HttpClient _http = new();
private readonly HttpClient _http;
private readonly Action<YouTubeChannel>? _sessionChanged;
public YouTubeChannel? CurrentChannel { get; private set; }
public YouTubeAuthService(string clientId, string clientSecret)
public YouTubeAuthService(string clientId, string clientSecret, HttpClient? http = null,
Action<YouTubeChannel>? sessionChanged = null)
{
_clientId = clientId;
_clientSecret = clientSecret;
_http = http ?? new HttpClient();
_sessionChanged = sessionChanged;
}
/// <summary>Replaces the current session (used when a saved token loads at startup).</summary>
public void SetSession(YouTubeChannel channel)
{
CurrentChannel = channel;
}
public string GetAuthorizationUrl(string redirectUri)
@@ -136,6 +146,7 @@ public class YouTubeAuthService
CurrentChannel.AccessToken = tokenData.GetProperty("access_token").GetString()!;
CurrentChannel.TokenExpiry = DateTime.UtcNow.AddSeconds(tokenData.GetProperty("expires_in").GetInt32());
_sessionChanged?.Invoke(CurrentChannel);
return true;
}
@@ -162,6 +173,7 @@ public class YouTubeAuthService
TokenExpiry = DateTime.UtcNow.AddSeconds(expiresIn)
};
_sessionChanged?.Invoke(CurrentChannel);
return CurrentChannel;
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ External-facing logic: YouTube API, persistence. See
| File | Purpose |
|------|---------|
| `YouTubeAuthService.cs` | OAuth2 via Google: loopback callback (`http://localhost:8765/oauth2/callback`), token exchange, refresh, channel fetch. **Complete — but no token persistence yet** (DPAPI planned) |
| `YouTubeAuthService.cs` | OAuth2 via Google: loopback callback (`http://localhost:8765/oauth2/callback`), token exchange, refresh, channel fetch. Constructor takes optional `HttpClient` + `sessionChanged` callback (test seam + save hook); session persists via `Helpers/TokenStore` (DPAPI) |
| `YouTubeStreamService.cs` | Broadcast/stream management via the v3 API (`enableAutoStart/Stop`). **Not yet switched to the `variable` reusable stream** |
| `YouTubeChatService.cs` | Polls `liveChat/messages`, raises `MessageReceived`; `IDisposable` |
| `LayoutStore.cs` | SQLite persistence (`Microsoft.Data.Sqlite`) at `%APPDATA%\ytLlive\ytLlive.db`; assets stored as BLOBs keyed by SHA-256 content hash; save/open layout files |