How to retrieve the Microsoft Store ID key?
Asked Answered
S

2

14

I'm trying to learn how to retrieve the Microsoft Store ID key. For this, I followed the examples provided by Microsoft in Windows Universal Samples. I tried to use the Business to Business scenario (scenario 7). I already published a sample App and registered the app in Azure Active Directory. The problem is I don't know what value should I send as the publisherUserId parameter in the getCustomerCollectionsIdAsync/getCustomerPurchaseIdAsync functions. I tried to send the email of the current user (customer email) which only retrieves an empty result (Microsoft Store ID key).

 function getCustomerCollectionsId() {
    var token = getTokenFromAzureOAuthAsync().done(function (aadToken) {
        if (aadToken) {
            storeContext.getCustomerCollectionsIdAsync(aadToken, "***@hotmail.com")//"[email protected]"
                .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")//"[email protected]"
                .done(function (result) {
                    output.innerText = result;
                    if (!result) {
                        WinJS.log && WinJS.log("getCustomerPurchaseIdAsync failed.", "sample", "error");
                    }
                });
        }
    });
}
Successful answered 27/11, 2017 at 18:2 Comment(10)
The publisherUserId parameter is optional, If you maintain anonymous user IDs for use in their services, you could pass customer email as parameter. Could you tell the email you passed is customer or publisher?Consignment
@NicoZhu-MSFT the parameter passed as publisherUserId is a customer email.Poeticize
Have you tried not to pass publisherUserId parameter?Consignment
@NicoZhu-MSFT yes it throws an exception due to lack of arguments. (0x800a13ee - JavaScript runtime error: getCustomerCollectionsIdAsync: function called with too few arguments)Poeticize
I mean that you could pass null parameter as publisherUserId.Consignment
@NicoZhu-MSFT With the publisherUserId equals to null the result of both functions are empty (result = "").Poeticize
Having the exact same issue! I absolutely need to provide a value to get a Store ID, null or empty strings don't work and the value is NOT optional even though the docs say it is.Taxdeductible
@NicoZhu, any idea as a fix or workaround??Taxdeductible
Same issue hereExpansion
I come across the same problem, then I use charles ssl proxy to log that https request that uwp send to collections.mp.microsoft.com and get the detail error message like { "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" }Jackknife
J
1

I have face the same problem, here is the solution works for me.

Go to https://portal.azure.com ,choose "Azure Active Directory" , choose "App registrations" , choose your application in the right panel. then Choose Manifest to edit it manifest. set following fields to the value:

"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",

And the resource field of your get token request (https://login.microsoftonline.com/xxx/oauth2/token) must be the exact string "https://onestore.microsoft.com/b2b/keys/create/collections" (notice that the domain part is "onestore.microsoft.com")

ps: My way to find out this solution:

  • use charles ssl proxy to record request of my c# project with the storeContext.getCustomerCollectionsIdAsync api. find out that the url it send is "https://collections.mp.microsoft.com/v7.0/beneficiaries/me/keys" and the request body contain the token I send to it.
  • use charles ssl proxy to record request of other app that works correctly like "Hotspot Shield", try to buy something from it, and cancel it. Find the request of the url and download the request body and base64 raw url to decode the second part of their token, find that the "aud" is "https://onestore.microsoft.com/b2b/keys/create/collections" and "ver" is "1.0".
  • Change the config of the "App registrations" and the token get code to make the result token is version 1.0 and "aud" to the correct one.

I think that "Azure Active Directory" is update to version 2, but the document of "Microsoft Store ID key" is not update to that version ...

Jackknife answered 2/7, 2019 at 8:17 Comment(2)
version 1 is not allowed in this manifest, validation discards itHandbarrow
@Handbarrow It worked in 2019. I do not try it now..Jackknife
L
-1
using Windows.Security.Authentication.Web;
...
string SID = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();

You can try this if you are in the development phase. This will be helpful if you are stuck worrying about submitting the app to store to do something like Facebook authentication. Given below is the reference I got it from. Hope this helped!

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

Licking answered 11/7, 2018 at 9:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.