Skip to content

Commit

Permalink
Авторизация: документация, синхронные методы.
Browse files Browse the repository at this point in the history
  • Loading branch information
K1llMan committed Jan 9, 2023
1 parent dd45ad1 commit cec821f
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 25 deletions.
104 changes: 100 additions & 4 deletions docs/source/api/branches/user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ YUserAPI

.. code-block:: csharp
public async Task AuthorizeAsync(AuthStorage storage, string login, string password)
public Task AuthorizeAsync(AuthStorage storage, string login, string password)
Авторизация в асинхронном режиме с использованием логина и пароля.

Expand All @@ -22,7 +22,7 @@ YUserAPI

.. code-block:: csharp
public async Task AuthorizeAsync(AuthStorage storage, string token)
public Task AuthorizeAsync(AuthStorage storage, string token)
Авторизация в асинхронном режиме с использованием токена.

Expand All @@ -36,12 +36,108 @@ YUserAPI

.. code-block:: csharp
public async Task<YResponse<YAccountResult>> GetUserAuthAsync(AuthStorage storage)
public Task<YResponse<YAccountResult>> GetUserAuthAsync(AuthStorage storage)
Получение информации об авторизации в асинхронном режиме.

.. code-block:: csharp
public YResponse<YAccountResult> GetUserAuth(AuthStorage storage)
Получение информации об авторизации.
Получение информации об авторизации.

.. code-block:: csharp
public Task<YAuthTypes> CreateAuthSessionAsync(AuthStorage storage, string userName)
Создание сеанса и получение доступных методов авторизации в асинхронном режиме.

.. code-block:: csharp
public YAuthTypes CreateAuthSession(AuthStorage storage, string userName)
Создание сеанса и получение доступных методов авторизации.

.. code-block:: csharp
public Task<string> GetAuthQRLinkAsync(AuthStorage storage)
Получение ссылки на QR-код в асинхронном режиме.

.. code-block:: csharp
public string GetAuthQRLink(AuthStorage storage)
Получение ссылки на QR-код.

.. code-block:: csharp
public Task<bool> AuthorizeByQRAsync(AuthStorage storage)
Авторизация по QR-коду в асинхронном режиме.

.. code-block:: csharp
public bool AuthorizeByQR(AuthStorage storage)
Авторизация по QR-коду.

.. code-block:: csharp
public Task<YAuthCaptcha> GetCaptchaAsync(AuthStorage storage)
Получение данных captcha в асинхронном режиме.

.. code-block:: csharp
public YAuthCaptcha GetCaptcha(AuthStorage storage)
Получение данных captcha.

.. code-block:: csharp
public Task<YAuthBase> AuthorizeByCaptchaAsync(AuthStorage storage, string captchaValue)
Авторизация по captcha в асинхронном режиме.

.. code-block:: csharp
public YAuthBase AuthorizeByCaptcha(AuthStorage storage, string captchaValue)
Авторизация по captcha.

.. code-block:: csharp
public Task<YAuthLetter> GetAuthLetterAsync(AuthStorage storage)
Получение письма авторизации на почту пользователя в асинхронном режиме.

.. code-block:: csharp
public YAuthLetter GetAuthLetter(AuthStorage storage)
Получение письма авторизации на почту пользователя.

.. code-block:: csharp
public Task<YAccessToken> AuthorizeByLetterAsync(AuthStorage storage)
Авторизация после подтверждения входа через письмо в асинхронном режиме.

.. code-block:: csharp
public YAccessToken AuthorizeByLetter(AuthStorage storage)
Авторизация после подтверждения входа через письмо.

.. code-block:: csharp
public Task<YAccessToken> AuthorizeByAppPasswordAsync(AuthStorage storage, string password)
Авторизация с помощью пароля из приложения Яндекс в асинхронном режиме.

.. code-block:: csharp
public YAccessToken AuthorizeByAppPassword(AuthStorage storage, string password)
Авторизация с помощью пароля из приложения Яндекс.
49 changes: 49 additions & 0 deletions docs/source/client/root.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,55 @@ YandexMusicClient
Авторизация с использованием токена.


.. code-block:: csharp
public YAuthTypes CreateAuthSession(string userName)
Создание сеанса и получение доступных методов авторизации.

.. code-block:: csharp
public string GetAuthQRLink()
Получение ссылки на QR-код.

.. code-block:: csharp
public bool AuthorizeByQR()
Авторизация по QR-коду.

.. code-block:: csharp
public YAuthCaptcha GetCaptcha()
Получение данных captcha.

.. code-block:: csharp
public void AuthorizeByCaptcha(string captcha)
Авторизация по captcha.

.. code-block:: csharp
public YAuthLetter GetAuthLetter()
Получение письма авторизации на почту пользователя.

.. code-block:: csharp
public YAccessToken AuthorizeByLetter()
Авторизация после подтверждения входа через письмо.

.. code-block:: csharp
public YAccessToken AuthorizeByAppPassword(string password)
Авторизация с помощью пароля из приложения Яндекс.

.. code-block:: csharp
public YTrack GetTrack(string id)
Expand Down
78 changes: 74 additions & 4 deletions src/Yandex.Music.Api/API/YUserAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ public Task<YAuthTypes> CreateAuthSessionAsync(AuthStorage storage, string userN
/// <returns></returns>
public YAuthTypes CreateAuthSession(AuthStorage storage, string userName)
{
return CreateAuthSessionAsync(storage, userName)
.GetAwaiter()
.GetResult();
return CreateAuthSessionAsync(storage, userName).GetAwaiter().GetResult();
}

/// <summary>
Expand Down Expand Up @@ -229,6 +227,16 @@ public Task<string> GetAuthQRLinkAsync(AuthStorage storage)
});
}

/// <summary>
/// Получение ссылки на QR-код
/// </summary>
/// <param name="storage">Хранилище</param>
/// <returns></returns>
public string GetAuthQRLink(AuthStorage storage)
{
return GetAuthQRLinkAsync(storage).GetAwaiter().GetResult();
}

/// <summary>
/// Авторизация по QR-коду
/// </summary>
Expand All @@ -253,6 +261,16 @@ public Task<bool> AuthorizeByQRAsync(AuthStorage storage)
}
}

/// <summary>
/// Авторизация по QR-коду
/// </summary>
/// <param name="storage">Хранилище</param>
/// <returns></returns>
public bool AuthorizeByQR(AuthStorage storage)
{
return AuthorizeByQRAsync(storage).GetAwaiter().GetResult();
}

/// <summary>
/// Получение <see cref="YAuthCaptcha"/>
/// </summary>
Expand All @@ -268,6 +286,16 @@ public Task<YAuthCaptcha> GetCaptchaAsync(AuthStorage storage)
.GetResponseAsync();
}

/// <summary>
/// Получение <see cref="YAuthCaptcha"/>
/// </summary>
/// <param name="storage">Хранилище</param>
/// <returns></returns>
public YAuthCaptcha GetCaptcha(AuthStorage storage)
{
return GetCaptchaAsync(storage).GetAwaiter().GetResult();
}

/// <summary>
/// Авторизация по captcha
/// </summary>
Expand All @@ -284,6 +312,17 @@ public Task<YAuthBase> AuthorizeByCaptchaAsync(AuthStorage storage, string captc
.GetResponseAsync();
}

/// <summary>
/// Авторизация по captcha
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="captchaValue">Значение captcha</param>
/// <returns></returns>
public YAuthBase AuthorizeByCaptcha(AuthStorage storage, string captchaValue)
{
return AuthorizeByCaptchaAsync(storage, captchaValue).GetAwaiter().GetResult();
}

/// <summary>
/// Получение письма авторизации на почту пользователя
/// </summary>
Expand All @@ -296,6 +335,16 @@ public Task<YAuthLetter> GetAuthLetterAsync(AuthStorage storage)
.GetResponseAsync();
}

/// <summary>
/// Получение письма авторизации на почту пользователя
/// </summary>
/// <param name="storage">Хранилище</param>
/// <returns></returns>
public YAuthLetter GetAuthLetter(AuthStorage storage)
{
return GetAuthLetterAsync(storage).GetAwaiter().GetResult();
}

/// <summary>
/// Авторизация после подтверждения входа через письмо
/// </summary>
Expand All @@ -315,13 +364,23 @@ public Task<YAccessToken> AuthorizeByLetterAsync(AuthStorage storage)
return LoginByCookiesAsync(storage);
}

/// <summary>
/// Авторизация после подтверждения входа через письмо
/// </summary>
/// <param name="storage">Хранилище</param>
/// <returns></returns>
public YAccessToken AuthorizeByLetter(AuthStorage storage)
{
return AuthorizeByLetterAsync(storage).GetAwaiter().GetResult();
}

/// <summary>
/// Авторизация с помощью пароля из приложения Яндекс
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="password">Пароль</param>
/// <returns></returns>
public Task<YAccessToken> AuthorizeByAppPassword(AuthStorage storage, string password)
public Task<YAccessToken> AuthorizeByAppPasswordAsync(AuthStorage storage, string password)
{
if (storage.AuthToken == null || string.IsNullOrWhiteSpace(storage.AuthToken.CsfrToken))
throw new AuthenticationException($"Не найдена сессия входа. Выполните {nameof(CreateAuthSessionAsync)} перед использованием.");
Expand All @@ -338,6 +397,17 @@ public Task<YAccessToken> AuthorizeByAppPassword(AuthStorage storage, string pas
return LoginByCookiesAsync(storage);
}

/// <summary>
/// Авторизация с помощью пароля из приложения Яндекс
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="password">Пароль</param>
/// <returns></returns>
public YAccessToken AuthorizeByAppPassword(AuthStorage storage, string password)
{
return AuthorizeByAppPasswordAsync(storage, password).GetAwaiter().GetResult();
}

#endregion Основные функции
}
}
10 changes: 9 additions & 1 deletion src/Yandex.Music.Api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ YandexMusicApi
├── Users
│   ├── Authorize / Async (AuthStorage storage, string username, string password)
│   ├── Authorize / Async (AuthStorage storage, string token)
│   └── GetUserAuth / Async (AuthStorage storage)
│   ├── GetUserAuth / Async (AuthStorage storage)
│   ├── CreateAuthSession / Async (AuthStorage storage, string userName)
│   ├── GetAuthQRLink / Async (AuthStorage storage)
│   ├── AuthorizeByQR / Async (AuthStorage storage)
│   ├── GetCaptcha / Async (AuthStorage storage)
│   ├── AuthorizeByCaptcha / Async (AuthStorage storage, string captchaValue)
│   ├── GetAuthLetter / Async (AuthStorage storage)
│   ├── AuthorizeByLetter / Async (AuthStorage storage)
│   └── AuthorizeByAppPassword / Async (AuthStorage storage, string password)
├── Track
│   ├── Get / Async (AuthStorage storage, string trackId)
│   ├── Get / Async (AuthStorage storage, IEnumerable<string> trackIds)
Expand Down

0 comments on commit cec821f

Please sign in to comment.