Added commerce.zunes.me sign in for OpenZune

This commit is contained in:
Yoshi Askharoun
2022-06-24 01:45:39 -05:00
parent 7081c9a32c
commit c7253a50d5
5 changed files with 150 additions and 13 deletions
+53
View File
@@ -0,0 +1,53 @@
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Xml.Serialization;
using Zune.Xml.Commerce;
namespace Microsoft.Zune.Service
{
internal static partial class CommunityCommerce
{
static readonly XmlSerializer _signInRequestSerializer = new XmlSerializer(typeof(SignInRequest));
static readonly XmlSerializer _signInResponseSerializer = new XmlSerializer(typeof(SignInResponse));
static SignInResponse _memberInfo;
public static SignInResponse MemberInfo
{
get => _memberInfo;
private set
{
_memberInfo = value;
Culture = new CultureInfo(value.AccountInfo.Locale);
}
}
public static CultureInfo Culture { get; private set; }
public static bool IsSignedIn => Escargot.HasToken && MemberInfo != null;
public static void SignOut() => MemberInfo = null;
private static Stream GetSignInRequestBody()
{
var requestObj = new SignInRequest
{
TunerInfo = new TunerInfo
{
Version = Assembly.GetEntryAssembly()?.GetName()?.Version?.ToString()
}
};
var contentStream = new MemoryStream();
_signInRequestSerializer.Serialize(contentStream, requestObj);
contentStream.Position = 0;
return contentStream;
}
private static SignInResponse ReadSignInResponse(Stream stream)
{
return _signInResponseSerializer.Deserialize(stream) as SignInResponse;
}
}
}
+52
View File
@@ -0,0 +1,52 @@
#if OPENZUNE
using System.IO;
using System.Net.Http;
using System.Xml.Serialization;
using Zune.Xml.Commerce;
using ZuneUI;
namespace Microsoft.Zune.Service
{
partial class CommunityCommerce
{
private static readonly HttpClient _client = Escargot._client;
public static HRESULT TrySignIn()
{
if (!Escargot.HasToken)
return HRESULT._NS_E_SUBSCRIPTIONSERVICE_LOGIN_FAILED;
try
{
HttpRequestMessage request = new(HttpMethod.Post, "https://commerce.zunes.me/v5.0/en-US/account/signin");
request.Headers.UserAgent.ParseAdd("Zune/5.0");
var contentStream = GetSignInRequestBody();
request.Content = new StreamContent(contentStream);
request.Content.Headers.ContentType = new(Atom.Constants.ATOM_MIMETYPE);
request.Content.Headers.ContentLength = contentStream.Length;
Escargot.AuthenticateRequest(request);
var response = _client.Send(request);
response.EnsureSuccessStatusCode();
var responseObj = ReadSignInResponse(response.Content.ReadAsStream());
uint? errorCode = responseObj?.AccountState?.SignInErrorCode;
if (errorCode != 0)
return new HRESULT(unchecked((int)errorCode));
MemberInfo = responseObj;
return HRESULT._S_OK;
}
catch
{
return HRESULT._NS_E_SUBSCRIPTIONSERVICE_LOGIN_FAILED;
}
}
}
}
#endif
+38 -12
View File
@@ -241,7 +241,9 @@ namespace Microsoft.Zune.Service
public string GetLocale()
{
return Service.Instance.GetLocale();
return CommunityCommerce.IsSignedIn
? CommunityCommerce.MemberInfo.AccountInfo.Locale
: null;
}
public string GetMachineId()
@@ -299,7 +301,12 @@ namespace Microsoft.Zune.Service
return Service.Instance.GetPhoneClientType(strPhoneOsVersion);
}
public int GetPointsBalance() => Service.Instance.GetPointsBalance();
public int GetPointsBalance()
{
return CommunityCommerce.IsSignedIn
? (int)CommunityCommerce.MemberInfo.Balances.PointsBalance
: 0;
}
public void GetPointsOffers(GetBillingOffersCompleteCallback completeCallback, GetBillingOffersErrorCallback errorCallback)
=> Service.Instance.GetPointsOffers(completeCallback, errorCallback);
@@ -344,11 +351,21 @@ namespace Microsoft.Zune.Service
public string GetWMISEndPointUri(string strEndPointName)
=> Service.Instance.GetWMISEndPointUri(strEndPointName);
public string GetXboxPuid() => Service.Instance.GetXboxPuid();
public string GetXboxPuid()
{
return CommunityCommerce.IsSignedIn
? CommunityCommerce.MemberInfo.AccountInfo.Xuid
: null;
}
public string GetXboxTicket() => Service.Instance.GetXboxTicket();
public string GetZuneTag() => Service.Instance.GetZuneTag();
public string GetZuneTag()
{
return CommunityCommerce.IsSignedIn
? CommunityCommerce.MemberInfo.AccountInfo.ZuneTag
: null;
}
public bool HasSignInBillingViolation() => Service.Instance.HasSignInBillingViolation();
@@ -381,13 +398,13 @@ namespace Microsoft.Zune.Service
public bool IsDownloading(Guid guidMediaId, EContentType eContentType, out bool fIsDownloadPending, out bool fIsHidden)
=> Service.Instance.IsDownloading(guidMediaId, eContentType, out fIsDownloadPending, out fIsHidden);
public bool IsLightWeight() => Service.Instance.IsLightWeight();
public bool IsLightWeight() => CommunityCommerce.IsSignedIn && CommunityCommerce.MemberInfo.AccountInfo.Lightweight;
public bool IsParentallyControlled() => Service.Instance.IsParentallyControlled();
public bool IsParentallyControlled() => CommunityCommerce.IsSignedIn && CommunityCommerce.MemberInfo.AccountInfo.ParentallyControlled;
public bool IsSignedIn() => Escargot.HasToken;
public bool IsSignedIn() => CommunityCommerce.IsSignedIn;
public bool IsSignedInWithSubscription() => Service.Instance.IsSignedInWithSubscription();
public bool IsSignedInWithSubscription() => CommunityCommerce.IsSignedIn && CommunityCommerce.MemberInfo.SubscriptionInfo.SubscriptionEnabled;
public bool IsSigningIn() => Service.Instance.IsSigningIn();
@@ -439,13 +456,21 @@ namespace Microsoft.Zune.Service
public void SignIn(string strUsername, string strPassword, bool fRememberUsername, bool fRememberPassword, bool fAutomaticallySignInAtStartup, AsyncCompleteHandler eventHandler)
{
bool success = Escargot.TrySignIn(strUsername, strPassword);
if (success && fRememberPassword)
HRESULT hr = Escargot.TrySignIn(strUsername, strPassword) ? HRESULT._S_OK : HRESULT._NS_E_PASSPORT_LOGIN_FAILED;
if (hr.IsSuccess)
{
Escargot.CacheToken();
#if OPENZUNE
hr = CommunityCommerce.TrySignIn();
#endif
if (hr.IsSuccess)
{
if (fRememberPassword)
Escargot.CacheToken();
}
}
int hr = success ? 0 : unchecked((int)0x80070057);
eventHandler(hr);
}
@@ -457,6 +482,7 @@ namespace Microsoft.Zune.Service
public void SignOut()
{
Escargot.ClearToken();
CommunityCommerce.SignOut();
}
public bool SubscriptionPendingCancel() => Service.Instance.SubscriptionPendingCancel();
+6 -1
View File
@@ -7,7 +7,7 @@ namespace Microsoft.Zune.Service
{
partial class Escargot
{
private static readonly HttpClient _client = new();
internal static readonly HttpClient _client = new();
public static bool TrySignIn(string username, string password)
{
@@ -29,6 +29,11 @@ namespace Microsoft.Zune.Service
return false;
}
}
public static void AuthenticateRequest(HttpRequestMessage request)
{
request.Headers.Authorization = new("Bearer", _token);
}
}
}
+1
View File
@@ -25,6 +25,7 @@
<!-- This is the last version of NAudio to support net35 and net6.0 -->
<PackageReference Include="NAudio" Version="1.10.0" />
<PackageReference Include="Zune.Xml" Version="0.1.0" />
<ProjectReference Include="..\libs\MicrosoftIris\UIX\UIX.csproj" />
</ItemGroup>