如何检索Microsoft Store ID密钥?

14

我正在尝试学习如何检索Microsoft Store ID密钥。为此,我遵循了Microsoft在Windows通用示例中提供的示例。 我尝试使用Business to Business方案(方案7)。 我已经发布了一个样例应用程序并在Azure Active Directory中注册了该应用程序。 问题是我不知道在getCustomerCollectionsIdAsync / getCustomerPurchaseIdAsync函数中应该发送什么值作为publisherUserId参数。 我尝试发送当前用户的电子邮件(客户电子邮件),但只检索到空结果(Microsoft Store ID密钥)。

 function getCustomerCollectionsId() {
    var token = getTokenFromAzureOAuthAsync().done(function (aadToken) {
        if (aadToken) {
            storeContext.getCustomerCollectionsIdAsync(aadToken, "***@hotmail.com")//"kim@example.com"
                .done(function (result) {
                    output.innerText = result;
                    if (!result) {
                        WinJS.log && WinJS.log("getCustomerCollectionsIdAsync failed.", "sample", "error");
                    }
                });
        }
    });
}

function getCustomerPurchaseId() {
    var token = getTokenFromAzureOAuthAsync().done(function (aadToken) {
        if (aadToken) {
            storeContext.getCustomerPurchaseIdAsync(aadToken, "***@hotmail.com")//"kim@example.com"
                .done(function (result) {
                    output.innerText = result;
                    if (!result) {
                        WinJS.log && WinJS.log("getCustomerPurchaseIdAsync failed.", "sample", "error");
                    }
                });
        }
    });
}

publisherUserId 参数是可选的,如果您维护匿名用户ID以供其服务使用,则可以将 customer email 作为参数传递。您能告诉我您传递的电子邮件是客户还是发布者吗? - Nico Zhu
@NicoZhu-MSFT,传递的参数publisherUserId是客户电子邮件。 - André Freitas
遇到完全相同的问题!我绝对需要提供一个值来获取 Store ID,null 或空字符串都不起作用,即使文档说它是可选的,但这个值并非可选。 - Maximus
@NicoZhu,有什么修复或解决方法吗? - Maximus
1
我遇到了同样的问题,然后我使用Charles SSL代理来记录UWP发送到https://collections.mp.microsoft.com的HTTPS请求,并获取详细的错误消息,如下: { "code": "Unauthorized", "data": [], "details": [], "innererror": { "code": "AuthenticationTokenInvalid", "data": [], "details": [], "message": "Authentication token supplied is invalid" }, "message": "The client is not authorized to perform the requested operation.", "source": "CollectionsFD" } - bronze man
显示剩余5条评论
2个回答

1

我也遇到了同样的问题,以下是解决方法。

打开 https://portal.azure.com ,选择“Azure Active Directory”,选择“应用注册”,在右侧面板中选择您的应用程序。接着选择"Manifest"编辑它的清单。将以下字段设置为如下值:

"accessTokenAcceptedVersion": 1,
"identifierUris": [
    "https://onestore.microsoft.com",
    "https://onestore.microsoft.com/b2b/keys/create/collections",
    "https://onestore.microsoft.com/b2b/keys/create/purchase"
    ],
"signInAudience": "AzureADMyOrg",

您的获取令牌请求(https://login.microsoftonline.com/xxx/oauth2/token)的资源字段必须是确切的字符串 "https://onestore.microsoft.com/b2b/keys/create/collections"(注意域部分为 "onestore.microsoft.com")

附注: 我找到此解决方案的方法:

  • 使用Charles SSL代理记录我的C#项目中storeContext.getCustomerCollectionsIdAsync API的请求。发现它发送的URL是 "https://collections.mp.microsoft.com/v7.0/beneficiaries/me/keys",请求正文包含我发送给它的令牌。
  • 使用Charles SSL代理记录其他正确工作的应用程序(如“热点盾”)的请求,尝试购买并取消。找到URL的请求,下载请求正文和base64原始URL以解码其令牌的第二部分,发现“aud”是 "https://onestore.microsoft.com/b2b/keys/create/collections",而“ver”是“1.0”。
  • 更改“应用程序注册”的配置和令牌获取代码,使结果令牌为版本1.0,“aud”为正确的值。

我认为“Azure Active Directory”已更新到版本2,但“Microsoft Store ID key”的文档尚未更新到该版本...


此清单不允许使用版本1,验证将会丢弃它。 - vehsakul
@vehsakul 它在2019年可以工作。我现在没有尝试过。 - bronze man

-1
using Windows.Security.Authentication.Web;
...
string SID = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();

如果你正在开发阶段,可以尝试这个方法。如果你被困在提交应用程序到商店的问题上,比如Facebook身份验证,这将非常有帮助。下面是我从参考资料中得到的内容。希望这能帮到你!

http://microsoft.github.io/winsdkfb/index.html


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接