Skip to content

Commit

Permalink
Enable Microsoft Entra Id auth for displaycatalog and use enterprise …
Browse files Browse the repository at this point in the history
…offline sku (#4544)
  • Loading branch information
yao-msft authored Jun 13, 2024
1 parent 59b794b commit 06ac471
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
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 @@ azurewebsites
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
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
1 change: 1 addition & 0 deletions src/AppInstallerCommonCore/Public/winget/MSStoreDownload.h
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;
};
}

0 comments on commit 06ac471

Please sign in to comment.