From 611a13f48b927777e1191a05ac472c25b423f347 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 12 Oct 2023 14:26:14 -0300 Subject: [PATCH 1/2] GenJWT falls back to the deprecated API --- storeapi/base/impl/StoreContext.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/storeapi/base/impl/StoreContext.cpp b/storeapi/base/impl/StoreContext.cpp index 0d155b4f4..54ed91f61 100644 --- a/storeapi/base/impl/StoreContext.cpp +++ b/storeapi/base/impl/StoreContext.cpp @@ -2,6 +2,7 @@ #include "StoreContext.hpp" +#include #include #include #include @@ -101,9 +102,14 @@ std::vector StoreContext::GetProducts( std::string StoreContext::GenerateUserJwt(std::string token, std::string userId) const { assert(!token.empty() && "Azure AD token is required"); - auto hJwt = self.GetCustomerPurchaseIdAsync(winrt::to_hstring(token), - winrt::to_hstring(userId)) - .get(); + auto hToken = winrt::to_hstring(token); + auto hUserId = winrt::to_hstring(userId); + auto hJwt = self.GetCustomerPurchaseIdAsync(hToken, hUserId).get(); + if (hJwt.empty()) { + hJwt = winrt::Windows::ApplicationModel::Store::CurrentApp:: + GetCustomerPurchaseIdAsync(hToken, hUserId) + .get(); + } return winrt::to_string(hJwt); } From e1511e63dfafb563144101134e33c856598102a2 Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 17 Oct 2023 10:24:34 -0300 Subject: [PATCH 2/2] Comment summarizing the reason for the fallback --- storeapi/base/impl/StoreContext.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/storeapi/base/impl/StoreContext.cpp b/storeapi/base/impl/StoreContext.cpp index 54ed91f61..bc78431a4 100644 --- a/storeapi/base/impl/StoreContext.cpp +++ b/storeapi/base/impl/StoreContext.cpp @@ -106,6 +106,12 @@ std::string StoreContext::GenerateUserJwt(std::string token, auto hUserId = winrt::to_hstring(userId); auto hJwt = self.GetCustomerPurchaseIdAsync(hToken, hUserId).get(); if (hJwt.empty()) { + // Although the preferred API for the MS Store is the one exported in the + // `Windows::Services::Store` namespace, it has consistently and silently + // failed to generate the user JWT, producing just an empty string. The old + // (deprecated) `Windows::ApplicationModel::Store` namespace, on the other + // hand, succeeded consistently in my tests, as long as the app is deployed + // (throwing exceptions otherwise). hJwt = winrt::Windows::ApplicationModel::Store::CurrentApp:: GetCustomerPurchaseIdAsync(hToken, hUserId) .get();