Переделан способ авторизации по qr
All checks were successful
Release / pack-and-publish (release) Successful in 1m5s
All checks were successful
Release / pack-and-publish (release) Successful in 1m5s
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using YandexMusic.API.Models.Account;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
|
||||
@@ -8,7 +9,47 @@ internal class YGetAuthCookiesBuilder : YAuthRequestBuilder<YAccessToken?, objec
|
||||
{
|
||||
public YGetAuthCookiesBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Post;
|
||||
protected override string BaseUrl => YConstants.Endpoints.MobilePassportUrl;
|
||||
protected override string PathTemplate => "1/bundle/oauth/token_by_sessionid";
|
||||
protected override HttpContent? GetContent(object _)
|
||||
=> new FormUrlEncodedContent(new Dictionary<string, string> { { "client_id", YConstants.XClientId }, { "client_secret", YConstants.XClientSecret } });
|
||||
protected override void SetCustomHeaders(HttpRequestHeaders headers)
|
||||
{
|
||||
base.SetCustomHeaders(headers);
|
||||
headers.Add("ya-client-host", "passport.yandex.ru");
|
||||
|
||||
var cookieString = GetCookieString();
|
||||
if (!string.IsNullOrEmpty(cookieString))
|
||||
headers.Add("Ya-Client-Cookie", cookieString);
|
||||
}
|
||||
private string GetCookieString()
|
||||
{
|
||||
var container = Storage.CookieContainer;
|
||||
if (container == null) return string.Empty;
|
||||
|
||||
var uris = new[]
|
||||
{
|
||||
new Uri("https://yandex.ru"),
|
||||
new Uri("https://passport.yandex.ru"),
|
||||
new Uri("https://mobileproxy.passport.yandex.net")
|
||||
};
|
||||
|
||||
var cookies = new List<string>();
|
||||
foreach (var uri in uris)
|
||||
{
|
||||
var cookieCollection = container.GetCookies(uri);
|
||||
foreach (Cookie cookie in cookieCollection)
|
||||
{
|
||||
cookies.Add($"{cookie.Name}={cookie.Value}");
|
||||
}
|
||||
}
|
||||
|
||||
var distinct = cookies
|
||||
.Select(c => c.Split('=')[0])
|
||||
.Distinct()
|
||||
.Select(name => cookies.First(c => c.StartsWith(name + "=")))
|
||||
.ToList();
|
||||
|
||||
return string.Join("; ", distinct);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using YandexMusic.API.Models.Account;
|
||||
|
||||
namespace YandexMusic.API.Requests.Account;
|
||||
|
||||
internal class YGetAuthLoginQRBuilder : YAuthRequestBuilder<YAuthQRStatus, string>
|
||||
internal class YGetAuthLoginQRBuilder : YAuthRequestBuilder<YAuthQRSession, string>
|
||||
{
|
||||
public YGetAuthLoginQRBuilder(YandexMusicApi yandex) : base(yandex)
|
||||
{
|
||||
@@ -11,13 +12,17 @@ internal class YGetAuthLoginQRBuilder : YAuthRequestBuilder<YAuthQRStatus, strin
|
||||
|
||||
protected override string Method => WebRequestMethods.Http.Post;
|
||||
|
||||
protected override string PathTemplate => "auth/new/magic/status/";
|
||||
protected override string PathTemplate => "pwl-yandex/api/passport/sessions/get_session";
|
||||
|
||||
protected override HttpContent GetContent(string tuple)
|
||||
{
|
||||
return new FormUrlEncodedContent(new Dictionary<string, string> {
|
||||
{ "csrf_token", Api.Storage.AuthToken.CsfrToken },
|
||||
{ "track_id", Api.Storage.AuthToken.TrackId }
|
||||
{ "track_id", Api.Storage.AuthToken.SessionTrackId }
|
||||
});
|
||||
}
|
||||
protected override void SetCustomHeaders(HttpRequestHeaders headers)
|
||||
{
|
||||
headers.Add("X-Csrf-Token", Api.Storage.HeaderToken.CsfrToken);
|
||||
headers.Add("Process-Uuid", Api.Storage.HeaderToken.ProcessUuid);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ internal class YGetAuthQRBuilder : YAuthRequestBuilder<YAuthQR?, object>
|
||||
=> new FormUrlEncodedContent(new Dictionary<string, string> { { "retpath", "" } });
|
||||
protected override void SetCustomHeaders(HttpRequestHeaders headers)
|
||||
{
|
||||
headers.Add("X-Csrf-Token", Api.Storage.AuthToken.CsfrToken);
|
||||
headers.Add("Process-Uuid", Api.Storage.AuthToken.ProcessUuid);
|
||||
headers.Add("X-Csrf-Token", Api.Storage.HeaderToken.CsfrToken);
|
||||
headers.Add("Process-Uuid", Api.Storage.HeaderToken.ProcessUuid);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ internal class YPostAuthStats : YAuthRequestBuilder<YAuthEmpty?, object>
|
||||
=> new FormUrlEncodedContent(new Dictionary<string, string> { { "messageType", "CLIENT_READY" } });
|
||||
protected override void SetCustomHeaders(HttpRequestHeaders headers)
|
||||
{
|
||||
headers.Add("X-Csrf-Token", Api.Storage.AuthToken.CsfrToken);
|
||||
headers.Add("Process-Uuid", Api.Storage.AuthToken.ProcessUuid);
|
||||
headers.Add("X-Csrf-Token", Api.Storage.HeaderToken.CsfrToken);
|
||||
headers.Add("Process-Uuid", Api.Storage.HeaderToken.ProcessUuid);
|
||||
}
|
||||
}
|
||||
23
YandexMusic.API/Requests/Account/YPostQrStatus.cs
Normal file
23
YandexMusic.API/Requests/Account/YPostQrStatus.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using YandexMusic.API.Models.Account;
|
||||
|
||||
namespace YandexMusic.API.Requests.Account;
|
||||
|
||||
internal class YPostQrStatus : YAuthRequestBuilder<YAuthQRStatus?, object>
|
||||
{
|
||||
public YPostQrStatus(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Post;
|
||||
protected override string PathTemplate => "pwl-yandex/api/passport/auth/magic/code/status";
|
||||
protected override HttpContent? GetContent(object _)
|
||||
=> new FormUrlEncodedContent(new Dictionary<string, string>
|
||||
{
|
||||
["csrf_token"] = Api.Storage.AuthToken.CsfrToken,
|
||||
["track_id"] = Api.Storage.AuthToken.TrackId,
|
||||
});
|
||||
protected override void SetCustomHeaders(HttpRequestHeaders headers)
|
||||
{
|
||||
headers.Add("X-Csrf-Token", Api.Storage.HeaderToken.CsfrToken);
|
||||
headers.Add("Process-Uuid", Api.Storage.HeaderToken.ProcessUuid);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user