Доработана QR авторизация

This commit is contained in:
FrigaT
2026-04-20 16:06:47 +03:00
parent 12241639dc
commit 9c95e6b189
11 changed files with 784 additions and 45 deletions

View File

@@ -2,7 +2,6 @@
using PlaylistShared.Api.Entities;
using System.Net;
using YandexMusic;
using YandexMusic.API.Common;
namespace PlaylistShared.Api.Services;
@@ -12,7 +11,6 @@ namespace PlaylistShared.Api.Services;
public class YandexApiService : IDisposable
{
private readonly IDataProtector _dataProtector;
private readonly HttpClient _httpClient;
private readonly YandexMusicClient _client;
private readonly CookieContainer _cookieContainer;
@@ -33,12 +31,7 @@ public class YandexApiService : IDisposable
{
_dataProtector = provider.CreateProtector("YandexTokens");
_cookieContainer = new();
_httpClient = YandexMusicHttpClientFactory.CreateDefault(
cookieContainer: _cookieContainer,
proxy: proxy,
timeout: timeout
);
_client = new YandexMusicClient(_httpClient);
_client = new YandexMusicClient(_cookieContainer, proxy, timeout);
}
@@ -107,21 +100,6 @@ public class YandexApiService : IDisposable
return cookie?.Value;
}
private void UpdateHttpClientCookieContainer(CookieContainer container)
{
var handler = GetInnerHandler(_httpClient);
if (handler is HttpClientHandler httpHandler)
httpHandler.CookieContainer = container;
}
private static HttpMessageHandler GetInnerHandler(HttpClient client)
{
var field = client.GetType().GetField("_handler", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (field?.GetValue(client) is HttpMessageHandler handler)
return handler;
return new HttpClientHandler();
}
/// <summary>
/// Авторизуется с помощью OAuth-токена.
/// </summary>
@@ -133,6 +111,5 @@ public class YandexApiService : IDisposable
public void Dispose()
{
_client.Dispose();
_httpClient.Dispose();
}
}