> ## Documentation Index
> Fetch the complete documentation index at: https://docs.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.

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](https://docs.xbox.com/publishing/xstore-commerce/xstore-license-tokens.md) 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](https://docs.xbox.com/reference/system/xstore/functions/xstorecreatecontext.md).

*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\*](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md)

An [XAsyncBlock](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md) defining the asynchronous work being done. The [XAsyncBlock](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md) can be used to poll for the call's status and retrieve call results. See [XAsyncBlock](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md) 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](https://docs.xbox.com/reference/system/xstore/functions/xstorequerylicensetokenresult.md) after calling this function. To retrieve the size of the JSON web token call [XStoreQueryLicenseTokenResultSize](https://docs.xbox.com/reference/system/xstore/functions/xstorequerylicensetokenresultsize.md) 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](https://docs.xbox.com/publishing/xstore-commerce/xstore-granting-access.md)
* [Enabling licensing testing](https://docs.xbox.com/publishing/xstore-commerce/xstore-licensing-setup.md)
* [Basic DRM and license checks](https://docs.xbox.com/publishing/xstore-commerce/xstore-pc.md)
* [Using License Tokens to validate licensing on your services](https://docs.xbox.com/publishing/xstore-commerce/xstore-license-tokens.md)

## See also

[XStore](https://docs.xbox.com/reference/system/xstore/xstore_members.md)

[License Tokens Overview](https://docs.xbox.com/publishing/xstore-commerce/xstore-license-tokens.md)

[XStoreQueryLicenseTokenResult](https://docs.xbox.com/reference/system/xstore/functions/xstorequerylicensetokenresult.md)

[XStoreQueryLicenseTokenResultSize](https://docs.xbox.com/reference/system/xstore/functions/xstorequerylicensetokenresultsize.md)


## Related topics

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