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

Enable Microsoft Entra Id auth for displaycatalog and use enterprise offline sku #4544

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
bcp
BEFACEF
BFirst
bght
bght

Check warning on line 43 in .github/actions/spelling/expect.txt

View workflow job for this annotation

GitHub Actions / Check Spelling

entry has inconsistent line ending (unexpected-line-ending)
bigcatalog
BITMAPINFOHEADER
bitspace
bkup
Expand Down Expand Up @@ -362,7 +363,7 @@
PSHOST
psobject
ptstr
publickey

Check warning on line 366 in .github/actions/spelling/expect.txt

View workflow job for this annotation

GitHub Actions / Check Spelling

entry has inconsistent line ending (unexpected-line-ending)
PVD
pvk
pvm
Expand Down Expand Up @@ -412,8 +413,8 @@
servercertificate
setmetadatabymanifestid
SETTINGCHANGE
SETTINGMAPPING

Check warning on line 416 in .github/actions/spelling/expect.txt

View workflow job for this annotation

GitHub Actions / Check Spelling

entry has inconsistent line ending (unexpected-line-ending)
sfs

Check warning on line 417 in .github/actions/spelling/expect.txt

View workflow job for this annotation

GitHub Actions / Check Spelling

entry has inconsistent line ending (unexpected-line-ending)
sfsclient
SHCONTF
SHGDN
Expand All @@ -435,7 +436,7 @@
srs
startswith
STARTUPINFOW
STDMETHODCALLTYPE

Check warning on line 439 in .github/actions/spelling/expect.txt

View workflow job for this annotation

GitHub Actions / Check Spelling

entry has inconsistent line ending (unexpected-line-ending)
storeapps
storeorigin
STRRET
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLITests/MSStoreDownloadFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ utility::string_t TestDisplayCatalogResponse = _XPLATSTR(
"DisplaySkuAvailabilities": [
{
"Sku": {
"SkuId": "0010",
"SkuId": "0015",
"Properties": {
"Packages": [
{
Expand Down
29 changes: 21 additions & 8 deletions src/AppInstallerCommonCore/MSStoreDownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace AppInstaller::MSStore
namespace DisplayCatalogDetails
{
// Default preferred sku to use
constexpr std::string_view TargetSkuIdValue = "0010"sv;
constexpr std::string_view TargetSkuIdValue = "0015"sv;

// Json response fields
constexpr std::string_view Product = "Product"sv;
Expand All @@ -67,9 +67,10 @@ namespace AppInstaller::MSStore
constexpr std::string_view WuCategoryId = "WuCategoryId"sv;

// Display catalog rest endpoint
constexpr std::string_view DisplayCatalogRestApi = R"(https://displaycatalog.mp.microsoft.com/v7.0/products/{0}?fieldsTemplate={1}&market={2}&languages={3})";
constexpr std::string_view DisplayCatalogRestApi = R"(https://displaycatalog.mp.microsoft.com/v7.0/products/{0}?fieldsTemplate={1}&market={2}&languages={3}&catalogIds={4})";
constexpr std::string_view Details = "Details"sv;
constexpr std::string_view Neutral = "Neutral"sv;
constexpr std::string_view TargetCatalogId = "4"sv;

enum class DisplayCatalogPackageFormatEnum
{
Expand Down Expand Up @@ -411,7 +412,7 @@ namespace AppInstaller::MSStore
locales.emplace_back(Neutral);

auto restEndpoint = AppInstaller::Utility::Format(std::string{ DisplayCatalogRestApi },
productId, Details, AppInstaller::Runtime::GetOSRegion(), Utility::Join(Utility::LocIndView(","), locales));
productId, Details, AppInstaller::Runtime::GetOSRegion(), Utility::Join(Utility::LocIndView(","), locales), TargetCatalogId);

return JSON::GetUtilityString(restEndpoint);
}
Expand All @@ -422,7 +423,7 @@ namespace AppInstaller::MSStore
// "DisplaySkuAvailabilities": [
// {
// "Sku": {
// "SkuId": "0010",
// "SkuId": "0015",
// ... Sku Contents ...
// }
// }
Expand Down Expand Up @@ -570,7 +571,7 @@ namespace AppInstaller::MSStore
return displayCatalogPackages;
}

DisplayCatalogPackage CallDisplayCatalogAndGetPreferredPackage(std::string_view productId, std::string_view locale, Utility::Architecture architecture)
DisplayCatalogPackage CallDisplayCatalogAndGetPreferredPackage(std::string_view productId, std::string_view locale, Utility::Architecture architecture, const Http::HttpClientHelper::HttpRequestHeaders& authHeaders)
{
AICLI_LOG(Core, Info, << "CallDisplayCatalogAndGetPreferredPackage with ProductId: " << productId << " Locale: " << locale << " Architecture: " << Utility::ToString(architecture));

Expand All @@ -585,7 +586,7 @@ namespace AppInstaller::MSStore
}
#endif

std::optional<web::json::value> displayCatalogResponseObject = httpClientHelper.HandleGet(displayCatalogApi);
std::optional<web::json::value> displayCatalogResponseObject = httpClientHelper.HandleGet(displayCatalogApi, {}, authHeaders);

if (!displayCatalogResponseObject)
{
Expand Down Expand Up @@ -1007,6 +1008,19 @@ namespace AppInstaller::MSStore
AppInstaller::Authentication::AuthenticationArguments authArgs) :
m_productId(std::move(productId)), m_architecture(architecture), m_platform(platform), m_locale(std::move(locale))
{
#ifndef AICLI_DISABLE_TEST_HOOKS
if (!TestHooks::s_DisplayCatalog_HttpPipelineStage_Override)
#endif
{
Authentication::MicrosoftEntraIdAuthenticationInfo displayCatalogMicrosoftEntraIdAuthInfo;
displayCatalogMicrosoftEntraIdAuthInfo.Resource = "https://bigcatalog.commerce.microsoft.com";
Authentication::AuthenticationInfo displayCatalogAuthInfo;
displayCatalogAuthInfo.Type = Authentication::AuthenticationType::MicrosoftEntraId;
displayCatalogAuthInfo.MicrosoftEntraIdInfo = std::move(displayCatalogMicrosoftEntraIdAuthInfo);

m_displayCatalogAuthenticator = std::make_unique<Authentication::Authenticator>(std::move(displayCatalogAuthInfo), authArgs);
}

#ifndef AICLI_DISABLE_TEST_HOOKS
if (!TestHooks::s_Licensing_HttpPipelineStage_Override)
#endif
Expand All @@ -1017,15 +1031,14 @@ namespace AppInstaller::MSStore
licensingAuthInfo.Type = Authentication::AuthenticationType::MicrosoftEntraId;
licensingAuthInfo.MicrosoftEntraIdInfo = std::move(licensingMicrosoftEntraIdAuthInfo);

// Not moving authArgs because we'll have auth for display catalog and sfs client in the near future.
m_licensingAuthenticator = std::make_unique<Authentication::Authenticator>(std::move(licensingAuthInfo), authArgs);
}
}

MSStoreDownloadInfo MSStoreDownloadContext::GetDownloadInfo()
{
#ifndef WINGET_DISABLE_FOR_FUZZING
auto displayCatalogPackage = DisplayCatalogDetails::CallDisplayCatalogAndGetPreferredPackage(m_productId, m_locale, m_architecture);
auto displayCatalogPackage = DisplayCatalogDetails::CallDisplayCatalogAndGetPreferredPackage(m_productId, m_locale, m_architecture, GetAuthHeaders(m_displayCatalogAuthenticator));
auto downloadInfo = SfsClientDetails::CallSfsClientAndGetMSStoreDownloadInfo(displayCatalogPackage.WuCategoryId, m_architecture, m_platform);
downloadInfo.ContentId = displayCatalogPackage.ContentId;
return downloadInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace AppInstaller::MSStore
AppInstaller::Utility::Architecture m_architecture = AppInstaller::Utility::Architecture::Unknown;
AppInstaller::Manifest::PlatformEnum m_platform = AppInstaller::Manifest::PlatformEnum::Unknown;
std::string m_locale;
std::unique_ptr<AppInstaller::Authentication::Authenticator> m_displayCatalogAuthenticator;
std::unique_ptr<AppInstaller::Authentication::Authenticator> m_licensingAuthenticator;
};
}
Loading