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;
}
}