> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XStoreQueryLicenseTokenAsync

> Reference for XStoreQueryLicenseTokenAsync, a GDK XStore licensing function that retrieves a JSON Web Token for entitlement validation and B2B calls.

# 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](/publishing/xstore-commerce/xstore-license-tokens) for more information.

## Syntax

```cpp theme={null}
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](/reference/system/xstore/functions/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\*](/reference/system/xasync/structs/xasyncblock)

An [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) defining the asynchronous work being done. The [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) can be used to poll for the call's status and retrieve call results. See [XAsyncBlock](/reference/system/xasync/structs/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](/reference/system/xstore/functions/xstorequerylicensetokenresult) after calling this function. To retrieve the size of the JSON web token call [XStoreQueryLicenseTokenResultSize](/reference/system/xstore/functions/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.

```cpp theme={null}
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

## Conceptual documentation

* [Granting players access to add-on content](/publishing/xstore-commerce/xstore-granting-access)
* [Enabling licensing testing](/publishing/xstore-commerce/xstore-licensing-setup)
* [Basic DRM and license checks](/publishing/xstore-commerce/xstore-pc)
* [Using License Tokens to validate licensing on your services](/publishing/xstore-commerce/xstore-license-tokens)

## See also

[XStore](/reference/system/xstore/xstore_members)

[License Tokens Overview](/publishing/xstore-commerce/xstore-license-tokens)

[XStoreQueryLicenseTokenResult](/reference/system/xstore/functions/xstorequerylicensetokenresult)

[XStoreQueryLicenseTokenResultSize](/reference/system/xstore/functions/xstorequerylicensetokenresultsize)


## Related topics

- [XStoreQueryLicenseTokenResult](/reference/system/xstore/functions/xstorequerylicensetokenresult.md)
- [XStoreQueryLicenseTokenResultSize](/reference/system/xstore/functions/xstorequerylicensetokenresultsize.md)
- [XStore on PC — DRM, license tokens, and sandboxes](/publishing/xstore-commerce/xstore-pc.md)
- [Basic DRM and license checks](/publishing/xstore-commerce/xstore-basic-drm.md)
- [Enabling licensing testing](/publishing/xstore-commerce/xstore-licensing-setup.md)
