Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storeapi): Allows fallback to the old API for JWT generation #337

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions storeapi/base/impl/StoreContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "StoreContext.hpp"

#include <winrt/Windows.ApplicationModel.Store.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Security.Cryptography.core.h>
Expand Down Expand Up @@ -101,9 +102,20 @@ std::vector<StoreContext::Product> 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);
}

Expand Down
Loading