> ## 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

> XStoreQueryLicenseTokenAsync

# XStoreQueryLicenseTokenAsync

呼び出し元のゲームに、エンタイトルメントの検証や B2B 呼び出しを行うためにゲームのサービスに渡すことができる、不透明な JSON Web トークンを提供します。詳細については、[ライセンス トークンの概要](/publishing/xstore-commerce/xstore-license-tokens)を参照してください。

## 構文

```cpp theme={null}
HRESULT XStoreQueryLicenseTokenAsync(  
         const XStoreContextHandle storeContextHandle,  
         const char** productIds,  
         size_t productIdsCount,  
         const char* customDeveloperString,  
         XAsyncBlock* async  
)  
```

### パラメーター

*storeContextHandle*   \_In\_\
Type: XStoreContextHandle

[XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext) から返される、ユーザーのストア コンテキスト ハンドル。

*productIds*   \_In\_z\_count\_(productIdsCount)\
Type: char\*\*

トークンを取得する対象の製品 ID の配列。

*productIdsCount*   \_In\_\
Type: size\_t

**productIds** に渡される配列内の ID の数。

*customDeveloperString*   \_In\_z\_\
Type: char\*

トークンにラウンド トリップされる値。これは通常サービスによって選択されます。userId や電子メールなどを挿入することで、ライセンス トークン内のユーザーのトークンを追跡できます。ライセンス トークンは所有権の受領証のように使用されます。

これは null または空の文字列にすることはできません。

*async*   \_Inout\_\
Type: [XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

実行中の非同期処理を定義する [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。[XAsyncBlock](/reference/system/xasync/structs/xasyncblock) は、呼び出しの状態のポーリングと呼び出し結果の取得に使用できます。詳細については、[XAsyncBlock](/reference/system/xasync/structs/xasyncblock) を参照してください。

### 戻り値

Type: HRESULT

HRESULT の成功またはエラー コード。

## 解説

JSON Web トークンとこの関数の実行結果を取得するには、この関数を呼び出した後に [XStoreQueryLicenseTokenResult](/reference/system/xstore/functions/xstorequerylicensetokenresult) を呼び出します。JSON Web トークンのサイズを取得するには、この関数を呼び出した後に [XStoreQueryLicenseTokenResultSize](/reference/system/xstore/functions/xstorequerylicensetokenresultsize) を呼び出します。トークンのサイズを事前に知ることで、より効率的に取得できます。

ライセンス トークンは Base64 エンコードされた JSON Web トークンです。トークンのペイロードは Base64 エンコードされた文字列で、サーバー上で検証に使用できる JSON 値に変換されます。

次のコード スニペットは、ライセンス トークンを取得する例を示しています。

```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;
    }
}
```

## 要件

**ヘッダー:** XStore.h (XGameRuntime.h に含まれる)

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One 本体および XBOX Series 本体

## 関連概念ドキュメント

* [プレイヤーにアドオン コンテンツへのアクセス権を付与する](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-granting-access-to-content)
* [ライセンス テストを有効にする](/publishing/xstore-commerce/xstore-licensing-setup)
* [基本的な DRM とライセンスのチェック](/publishing/xstore-commerce/xstore-pc)
* [ライセンス トークンを使用してサービスでライセンスを検証する](/publishing/xstore-commerce/xstore-license-tokens)

## 関連項目

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

[ライセンス トークンの概要](/publishing/xstore-commerce/xstore-license-tokens)

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

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


## Related topics

- [XStoreQueryLicenseTokenResult](/ja-jp/reference/system/xstore/functions/xstorequerylicensetokenresult.md)
- [XStoreQueryLicenseTokenResultSize](/ja-jp/reference/system/xstore/functions/xstorequerylicensetokenresultsize.md)
- [ライセンス供与テストの有効化](/ja-jp/publishing/xstore-commerce/xstore-licensing-setup.md)
- [PC 上の XStore — DRM、ライセンス トークン、サンドボックス](/ja-jp/publishing/xstore-commerce/xstore-pc.md)
- [プレイヤーにアドオン コンテンツへのアクセスを付与する](/ja-jp/publishing/xstore-commerce/xstore-granting-access.md)
