diff --git a/storeapi/base/impl/StoreContext.cpp b/storeapi/base/impl/StoreContext.cpp index 0d155b4f4..bc78431a4 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,20 @@ 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()) { + // 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(); + } return winrt::to_string(hJwt); }