mirror of
https://github.com/ZuneDev/ZuneShell.dll.git
synced 2026-07-27 13:11:51 -07:00
41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
#if OPENZUNE
|
|
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
|
|
namespace Microsoft.Zune.Service
|
|
{
|
|
partial class Escargot
|
|
{
|
|
internal static readonly HttpClient _client = new();
|
|
|
|
public static bool TrySignIn(string username, string password)
|
|
{
|
|
HttpRequestMessage request = new(HttpMethod.Post, ESCARGOT_NOTRST_URL);
|
|
request.Headers.TryAddWithoutValidation(HEADER_X_USER, username);
|
|
request.Headers.TryAddWithoutValidation(HEADER_X_PASS, password);
|
|
|
|
try
|
|
{
|
|
var response = _client.Send(request);
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
string token = response.Headers.GetValues(HEADER_X_TOKEN).FirstOrDefault();
|
|
|
|
return TrySetCredentials(token, username);
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static void AuthenticateRequest(HttpRequestMessage request)
|
|
{
|
|
request.Headers.Authorization = new("Bearer", _token);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|