Files
YandexMusic/YandexMusic.API/Common/AuthStorage.cs
2026-04-10 12:12:33 +03:00

103 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Net;
using YandexMusic.API.Common.Debug;
using YandexMusic.API.Common.Providers;
using YandexMusic.API.Models.Account;
using YandexMusic.API.Requests.Common;
namespace YandexMusic.API.Common
{
/// <summary>
/// Хранилище данных пользователя
/// </summary>
public class AuthStorage
{
#region Свойства
/// <summary>
/// Http-контекст
/// </summary>
public HttpContext Context { get; }
public DebugSettings Debug { get; set; }
/// <summary>
/// Флаг авторизации
/// </summary>
public bool IsAuthorized { get; internal set; }
/// <summary>
/// Идентификатор устройства
/// </summary>
public string DeviceId { get; set; } = "csharp";
/// <summary>
/// Токен авторизации
/// </summary>
public string Token { get; internal set; }
/// <summary>
/// Аккаунт
/// </summary>
public YAccount User { get; set; }
/// <summary>
/// Провайдер запросов
/// </summary>
public IRequestProvider Provider { get; }
/// <summary>
/// Токен доступа
/// </summary>
public YAccessToken AccessToken { get; set; }
internal YAuthToken AuthToken { get; set; }
#endregion Свойства
/// <summary>
/// Конструктор
/// </summary>
public AuthStorage(DebugSettings settings = null)
{
User = new YAccount();
Context = new HttpContext();
Debug = settings;
Provider = new DefaultRequestProvider(this);
if (Debug is { ClearDirectory: true })
{
Debug.Clear();
}
}
/// <summary>
/// Конструктор
/// </summary>
public AuthStorage(IRequestProvider provider, DebugSettings settings = null)
{
User = new YAccount();
Context = new HttpContext();
Debug = settings;
Provider = provider;
if (Debug is { ClearDirectory: true })
{
Debug.Clear();
}
}
/// <summary>
/// Установка прокси для пользователия
/// </summary>
/// <param name="proxy">Прокси</param>
public void SetProxy(IWebProxy proxy)
{
Context.WebProxy = proxy;
}
}
}