Unable to get access token for microsoft store service

Jacques O 0 Reputation points

Hi, I am building an app for the Microsoft Store. I require the app's server to connect to the microsoft store to validate purchases.

I'm using the Microsoft.StoreServices API provided at: https://github.com/microsoft/Microsoft-Store-Services

Basically when your server starts it should query Microsoft Azure AD (Entra ID) based on your tenant id, client id and client secret (using OAuth 2.0 with client_credentials flow to the token endpoint under the hood) and issue you an access token.

Basically I do:

//Startup.cs - InitializeMicrosoftStoreServicesCachedTokenProvider(...)
var cachedTokenProvider = new MicrosoftStoreServicesCachedTokenProvider(serverMemoryCache, myTenantId, myClientId, myClientSecret);
var serviceAccessToken = cachedTokenProvider.GetServiceAccessTokenAsync().Result;

I get a 400 Bad Request exception:

Microsoft.StoreServices.StoreServicesHttpResponseException: 'Unable to acquire access token for https://onestore.microsoft.com : Bad Request'

According to https://learn.microsoft.com/en-us/windows/uwp/monetize/view-and-grant-products-from-a-servic

I have an Azure AD (Entra Id) account with an app that has "Allow public client flows" turned on. However supported account types is "Personal Microsoft accounts only".

My app's client id is entered in Microsoft Partner Center, under "Product collections and purchases".

I tried using "consumers" also as a tenant id (sometimes required with oauth when using personal Microsoft accounts), with no luck.

This is the code underlying the call:

var requestUri = $"https://login.microsoftonline.com/{_tenantId}/oauth2/v2.0/token";
var httpRequest = new HttpRequestMessage(HttpMethod.Post, requestUri.ToString());
var requestBody = $"grant_type=client_credentials&client_id={_clientId}" +
                  $"&client_secret={encodedSecret}" +
httpRequest.Content = new StringContent(requestBody, Encoding.UTF8, "application/x-www-form-urlencoded");

Basically, I am wondering what I am doing wrong and how I may make that token request work.


A set of technologies in the .NET Framework for building web applications and XML web services.
4,312 questions
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,093 questions
Microsoft Partner Center
Microsoft Partner Center
A Microsoft website for partners that provides access to product support, a partner community, and other partner services.
907 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,534 questions
0 comments No comments
{count} votes