Freigeben über


XStoreQueryLicenseTokenAsync

Provides an opaque JSON Web Token to the calling game that can be passed to the game's service for validation of entitlement and to make B2B calls. See License Tokens Overview for more information.

Syntax

HRESULT XStoreQueryLicenseTokenAsync(  
         const XStoreContextHandle storeContextHandle,  
         const char** productIds,  
         size_t productIdsCount,  
         const char* customDeveloperString,  
         XAsyncBlock* async  
)  

Parameters

storeContextHandle   _In_
Type: XStoreContextHandle

The store context handle for the user returned by XStoreCreateContext.

productIds   _In_z_count_(productIdsCount)
Type: char**

An array of product IDs to retrieve tokens for.

productIdsCount   _In_
Type: size_t

The number of IDs in the array passed into productIds.

customDeveloperString   _In_z_
Type: char*

A value that is round tripped into the token. This is generally chosen by the service. You can insert something like a userId or email to track the user's token in the license token. A license token is used like a receipt of ownership.

This cannot be null or the empty string.

async   _Inout_
Type: XAsyncBlock*

An XAsyncBlock defining the asynchronous work being done. The XAsyncBlock can be used to poll for the call's status and retrieve call results. See XAsyncBlock for more information.

Return value

Type: HRESULT

HRESULT success or error code.

Remarks

To retrieve the JSON web token as well as the execution result of this function call XStoreQueryLicenseTokenResult after calling this function. To retrieve the size of the JSON web token call XStoreQueryLicenseTokenResultSize after calling this function. Know the size of the token will allow you to retrieve it more efficiently.

The license token is a Base64 encoded JSON Web Token. The token's payload is a Base64 encoded string that converts to JSON values that can be used on the server for validation.

The following code snippet shows an example of retrieving a license token.

void CALLBACK QueryLicenseTokenCallback(XAsyncBlock* asyncBlock)
{
    size_t size;
    HRESULT hr = XStoreQueryLicenseTokenResultSize(
        asyncBlock,
        &size);

    if (FAILED(hr))
    {
        printf("Failed retrieve the license token size: 0x%x\r\n", hr);
        return;
    }

    char* result = new char[size];
    hr = XStoreQueryLicenseTokenResult(
        asyncBlock,
        size,
        result);

    if (FAILED(hr))
    {
        printf("Failed retrieve the license token result: 0x%x\r\n", hr);
        delete[] result;
        return;
    }

    printf("result: %s\r\n", result);

    delete[] result;
}

void QueryLicenseToken(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char** productIds, size_t productIdsCount, const char* customDeveloperString)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = QueryLicenseTokenCallback;

    HRESULT hr = XStoreQueryLicenseTokenAsync(
        storeContextHandle,
        productIds,
        productIdsCount,
        customDeveloperString,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to get license token: 0x%x\r\n", hr);
        return;
    }
}

Requirements

Header: XStore.h (included in XGameRuntime.h)

Library: xgameruntime.lib

Supported platforms: Windows, Xbox One family consoles and Xbox Series consoles

See also

XStore

License Tokens Overview

XStoreQueryLicenseTokenResult

XStoreQueryLicenseTokenResultSize